0

Button to create new record for sub-table and with reference

Hello.

Apologize for my lack of knowledge in coding.

I have a button (Update_Storage) which is supposed to create a new record for a sub-table (History) and copy information in from another table (Storage).

While it does create the record and copies in the information from the other table, it doesn't create a reference to the current record.

Means the new record appears in the sub-table but not on the record from where I created it.  See the screenshots which might explain it a bit better than I do here.

This is the code I am using

let myID := this;
let k := sum(Storage.Usage);
let curRec := this;
let newRec := (create History);
newRec.(Date := today());
newRec.(Usage := k);
newRec.(myID := this)

Thanks in advance for any hint.

Bernd

3 replies

null
    • John_Halls
    • 2 yrs ago
    • Reported - view

    Very nearly there. If the reference field for the Backup table in History is called Backup then try

    let myID := this;
    let k := sum(Storage.Usage);
    let newRec := (create History);
    newRec.(Date := today());
    newRec.(Usage := k);
    newRec.(Backup := MyID)
    

    There's no need for let CurRec := this as you have already assigned MyID with this value in the first line.

    Regards John

    • John_Halls
    • 2 yrs ago
    • Reported - view

    Sorry, on the last line change MyID to myID.

    To take this code to the next level use

    let myID := this;
    (create History).(
        Backup := myID;
        Date := today();
        Usage := sum(Backup.Storage.Usage)
    )
    

    Regards John

    • NetSol Co., Ltd.
    • Bernd_Krell
    • 2 yrs ago
    • Reported - view

    Hello John.

    What a great help, it works perfectly now. 

    Thank you so much 🙏🙏🙏🙏🙏🙏

Content aside

  • Status Answered
  • 2 yrs agoLast active
  • 3Replies
  • 416Views
  • 2 Following