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

3replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • 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

    Like
  • 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

    Like 1
    • Bernd Krell
    • NetSol Co., Ltd.
    • Bernd_Krell
    • 1 mth ago
    • Reported - view

    Hello John.

    What a great help, it works perfectly now. 

    Thank you so much 🙏🙏🙏🙏🙏🙏

    Like
Like Follow
  • Status Answered
  • 1 mth agoLast active
  • 3Replies
  • 53Views
  • 2 Following