0

Limit number of records in a subtable

Hi,

I have a table Suscripciones and a subtable ´Planes Suscritos´.

What would be the way to limit that the user can create only one record in ´Planes Suscritos´?

 

Thanks.

Jaime

4 replies

null
    • Jaime_Blanco_Landau
    • 4 yrs ago
    • Reported - view

    Hi guys,

    any advise?

    Thanks.

    Jaime

    • Choices_Software_Dean
    • 4 yrs ago
    • Reported - view

    Below is one possible approach:

    1. Add UserName text field to subtable ´Planes Suscritos´.

    2. Add UserName := userName() to "Trigger on create" of subtable

    3. Add button to parent Suscripciones table with code:

    let u := userName();
    let s := (select 'Planes Suscritos')[UserName = u];
    let c := cnt(s);
    alert(c)

    That should return the count of the current username in the subtable. Use that count to create a script that limits the user to only creating one record. I do not have time to test this right now, but I hope it helps.

    • Choices_Software_Dean
    • 4 yrs ago
    • Reported - view

    userId() might be better than userName() in case user changes name.

    • Nick
    • 4 yrs ago
    • Reported - view

    Another approach, button for table Suscripciones:

    ---

    let t := this;
    let c := cnt(select ´Planes Suscritos´ where Relationship_Name = t);
    if c = 0 then
    let n := (create ´Planes Suscritos´);
    n.(Relationship_Name := t)
    else
    alert("Hold your horses, there is " + c + " record already")
    end

Content aside

  • 4 yrs agoLast active
  • 4Replies
  • 1055Views