0

Trigger after duplicate

I see you can trigger things based on either 'trigger on create' or 'trigger after update'.

 

It'd be really useful to be able to 'trigger after duplicate'.

 

For example we will often duplicate previous invoices to save time adding multiple items for a replicate order. However we must then also remember to change all the other details, order date, delivery address, etc etc. The same for 'Master Templates', we often use 'Master Templates' which are designated as so by using a tick field. Although when duplicating we'd prefer the tick field unticks, so that the new record isn't added to our list of Masters.

Would be grateful if you could give this some thought.

 

Thanks

 

Richard

5 replies

null
    • Mconneen
    • 5 yrs ago
    • Reported - view

    @Richard... You can do this via custom script / button.  Birger showed this example on a recent webinar.. 

     

    Basically ... lets assume you are currently positioned on the Invoice you wan to copy ...  you could put something like the following in a "duplicate" button.. (untested code)

    let t:= this;

    let newInvoice := create Invoice;

    newInvoice.FieldA := t.FieldA;

    newInvoice.FieldB := t.FieldB;

    (etc... Birger also showed how to loop through the associated Line Items and copy those too) 

    openRecord(newInvoice.Id);

    • Richard_Bramall
    • 5 yrs ago
    • Reported - view

    Hi,

     

    Thanks and apologies for my delay in response (I did write a reply previously but it all got deleted when I had to then log in!)

     

    This is useful to know, thank you the looping through records is the most important bit so perhaps I'll need a webinar to see exactly how to loop through all the associated line items

    • Mconneen
    • 5 yrs ago
    • Reported - view

    @Rich, 

    No worries..  Assume your invoice has a sub table called Items .. and a form something like 

    beforeCopy

    Notice there is ONE row in the Inovice table.. and it has TWO Items. 

    The code for the duplicate button

    theCode

    The keys above are.. 

    let newInvoice :=(create Invoice) ... this creates a new invoice record (AKA record #2). 

    for i in t.Items do  ..... this starts the for loop... 

        let newITem := (create Items); ...... this creates a new Item record.. 

        newItem.Invoice := newInvoice;  ...... this sets the parent / child relationship so it will show up under the proper invoice. 

    So after the copy.. 

    afterCopy

    Notice that there are now two records in the Invoice table.. and there are two additional Items.. with id's 3 and 4 .. meaning there are a total of four Items.. two that belong to Invoice 1 .. and two that belong to Invoice 2.    

    The rest of the code should be easy to understand. 

    Happy Ninox-ing.. 

    • Richard_Bramall
    • 5 yrs ago
    • Reported - view

    Perfect! Thanks @Mconneen ! This is exactly what I need and easy to understand 

    • Richard_Bramall
    • 5 yrs ago
    • Reported - view

    Perfect! Thanks @Mconneen ! This is exactly what I need and easy to understand 

Content aside

  • 5 yrs agoLast active
  • 5Replies
  • 1719Views