0

Duplicating records - Keep some data and clear/reset other data

I want to be able to duplicate a record, but only keep some of the data in some of the fields (all sorts of field types). 

I'm using these records as templates, keeping the necessary data while clearing out the other fields.

Example 1: One field is a Yes/No field that I use as a record lock.  When this record gets duplicated I want to unlock it (change from "Yes" to either "No" or "empty".

Example 2: One field is a table reference (associating a customer) that I want to disassociate in the duplicated record.

Any help on this would be GREATLY appreciate!

Thank you in advance!

12 replies

null
    • Nick
    • 5 yrs ago
    • Reported - view

    You can use something like this:

     

    let d := duplicate(this);
    d.('Yes / No' := false);
    d.(Customer := 0);
    popupRecord(d)

     

    This will duplicate the record and empties the fields: 'Yes / No'  and Customer.

    Αll other fields will be cloned.

    • wstarnes
    • 5 yrs ago
    • Reported - view

    Excellent! Thank you for your response. 

    Can you please tell me exactly where this code goes into each field setup? (e.g. Trigger after update, Display field on if?)

    Again, thank you in advance!

    • Nick
    • 5 yrs ago
    • Reported - view

    Create a button i.e. Duplicate and enter the code in the 'On click' box.

    • wstarnes
    • 5 yrs ago
    • Reported - view

    Got it! Fantastic!! Thank you!

    • Alejako
    • 4 yrs ago
    • Reported - view

    Interesting, It's possible use duplicathe (this) or similar function for duplicate a lot of select register?

    • Nick
    • 4 yrs ago
    • Reported - view

    This will duplicate ALL records in a table.

    ---

    for i in select Table do
    duplicate(i)

    end

    ---

    I couldn't find a way to double only the selected/filtered entries, yet.

    • Alejako
    • 4 yrs ago
    • Reported - view

    Thanks Nick I will test this, look, when you said "All records in a table",you know if is possible first apply some filters and only duplicate the selected register?

    • Alejako
    • 4 yrs ago
    • Reported - view

    The idea is: I have one table with montlhy invoices and some of them need generate all month and the idea is applied one automatic process on close the month (all 30'th) for this reason I think one way maybe select all invoices from X month duplicated this and apply a masive update to this lot. Really I don't know the better way from resolve this monthly process.

    • Nick
    • 4 yrs ago
    • Reported - view

    As I set I'm trying to find a way to insert filters in the loop, but no success until now...

    • Alejako
    • 4 yrs ago
    • Reported - view

    Hi Nick, 

    Please try this

    __

    let myMont := if month(today()) = 1 then 12 else month(today()) - 1 end;
    let myYear := if month(today()) = 1 then year(today()) - 1 else year(today()) end;
    for i in select Tabla1 where year('Invoice date') = myYear and month('Invoice date') = myMont do
    let new := duplicate(i);
    new.('Invoice date' := today())
    end

    __

    • Nick
    • 4 yrs ago
    • Reported - view

    @alejako,

    Great job!!!

     

    (I didn't put the ends at the end of the variables...)

    • robert.1
    • 3 yrs ago
    • Reported - view

    Thanks for all usefull information. Still a question: how can I include the following function: I want the duplicate record automatically contain a reference to the original record where it was copied from. How can I add this to the button script?

    Robert

Content aside

  • 3 yrs agoLast active
  • 12Replies
  • 3434Views