Cloning a record - Forum - Rollbase - Progress Community

Cloning a record

 Forum

Cloning a record

This question is not answered

Hi,

I have some unclarity's about cloning a record; This is the case: I have an order object and also related records (orderline, ordertyre and orderlynedetails are related (n:1) to order). In the case i clone the order record the orderlines should also be cloned but the original orderlines should be related to the old order; only the newly created orderlines should be connected to the new order. However all the related records (orderline, orderlinedetails and ordertyres are related to the newly created order!

Should i do something special so that the orginal orderline, orderlinedetails and ordertyres stay to the orginial order?

Kindly reply

All Replies
  • How are you cloning the records?

    I think that your requirement needs a Workflow action, a create new record trigger, and a data map.

    Setup the create new record trigger to use your data map then setup the workflow action to run the create new record trigger.

    *** Data maps support cloning of related records per your requirement. You should see the relationships that allow you to choose which should be cloned and which shouldn't at the bottom of your data map.

    Hope this helps.

  • Hello,
    Part of the cloning effort is also to get a new ordernummer through an automatic number-field.
    So i need to update that autonumber field, which is not possible through cloning (that is a bug as i understood).
    By using a mapping this is not possible (update autonumber field).
    And by using this mapping only a boolean is avail.
     
    I would need something like:
     
    var v_invoiceorderid = {!id};
     
     
    var v_num = rbv_api.selectNumber("select ordern_ordernumber from order ORDER by createdAt DESC");
     
    var v_num_orderline = 0;
     
    rbv_api.printArr(v_num);
     
    // We only want to be able to make a credit order if this order
    // has not yet been credited before
     
    if('{!orderl_iscredited}' !== true)
    {
      
                   var v_arr = new Array();
     
                   v_arr['ordern_ordernumber']                   = v_num + 1;
                  v_arr['status']                                                                              = 109964;            // aangemaakt
                   v_arr['orderm_axstatus']                                           = "";
                   v_arr['R_order_orderline']                                         = 0;
                   v_arr['R_order_ordertyre']                                        = 0;
                   v_arr['R_order_orderlinedetail']               = 0;
       
     
     
                   rbv_api.printArr(v_arr);
     
                   rbv_api.cloneRecord("order", v_invoiceorderid, v_arr);
     
                   // de huidige order krijgt een vinkje dat ie gecrediteerd is
     
                   rbv_api.setFieldValue("order", v_invoiceorderid, "orderl_iscredited", true);
                   rbv_api.setFieldValue("order", v_invoiceorderid, "ordern_creditedbyordernumber", (v_num + 1));
     
     /*
     
                   // Find the order that is the cloned one (the credit order)
     
        var v_newordernum = v_num + 1;
     
                   var v_creditorderid = rbv_api.selectNumber("SELECT id FROM order where ordern_ordernumber=?", v_newordernum);
     
                   rbv_api.println("De nieuwe order is: " + v_creditorderid);
     
                   // now we need to have the related orderlines of the first order
     
                   var v_orderlineids_invoiced = [];
     
                   v_orderlineids_invoiced = rbv_api.getRelatedIds("R295312", v_invoiceorderid);
       
        //rbv_api.printArr(v_orderlineids_invoiced);
     
        //rbv_api.println(v_orderlineids_invoiced.length);
     
                   var v_orderline_quantity             = 0;
                   var v_orderlineid                                          = 0;
        var v_num_orderline                                = 0;
     
                   var v_arrorderline = new Array();
     
      
      
        for(i=0; i<v_orderlineids_invoiced.length; i++)
          {
           
            // The orderline that is related to the first (invoiced) order
            v_orderlineid                          = v_orderlineids_invoiced[i];
     
            rbv_api.println(v_orderlineid);
           
                                  // find the quantity of that orderline
                                 v_orderline_quantity = rbv_api.selectNumber("select orderlinea_quantity from orderline WHERE id=?", v_orderlineid);
           
            // Find the latest orderline for a numberupdate
            v_num_orderline = rbv_api.selectNumber("select orderlinen_linenumber from orderline ORDER by createdAt DESC");
           
            // Set the needed variables
           
            
            v_arrorderline['orderlinen_linenumber']     = v_num_orderline + 1;
            v_arrorderline['orderlinea_quantity']                           = (0 - v_orderline_quantity);
            v_arrorderline['orderlinen_orderid']                             = v_creditorderid;
     
                                  rbv_api.printArr(v_arrorderline);      
            
            // Clone the record
            rbv_api.cloneRecord("orderline", v_orderlineid, v_arrorderline);
              
              
            
          }
          */
     
     
    } // end if({!orderl_iscredited} !== true)
     
    If possible please help.
     
    Regards, Wim
     
     
    Van: mpiscoso@gmail.com [mailto:bounce-mpiscosogmailcom@community.progress.com]
    Verzonden: maandag 21 november 2016 14:58
    Aan: TU.Rollbase@community.progress.com
    Onderwerp: RE: [Technical Users - Rollbase] Cloning a record
     
    Update from Progress Community
     

    How are you cloning the records?

    I think that your requirement needs a Workflow action, a create new record trigger, and a data map.

    Setup the create new record trigger to use your data map then setup the workflow action to run the create new record trigger.

    *** Data maps support cloning of related records per your requirement. You should see the relationships that allow you to choose which should be cloned and which shouldn't at the bottom of your data map.

    Hope this helps.

    View online

     

    You received this notification because you subscribed to the forum.  To unsubscribe from only this thread, go here.

    Flag this post as spam/abuse.

     
  • I see.

    If my understanding is correct, you've already tried using a Create New Trigger + Data Map?

    If not, I suggest you try that -- it would take out all this code that you have. (suggestion from my original reply).

    If you have, then might I suggest that in your data map, leave the auto-number field as "Not Mapped" or "Default Value".

    It might solve your +1 number issue.

    Hope this helps.

  • If all else fails, unfortunately, I think you'd have to abandon the cloneRecord() API and use the createRecord() API.

    I haven't used the cloneRecord() api myself because I've never encountered your auto-number issue when using create new record and data maps in the past.

    Please confirm if you've tried Create New Record (trigger type) + Data map.

    Hope this helps. 

  • Thank you for the clear suggestion:  I will definitely try and let you know.
    However it will take some time from now.
     
    Regards, Wim
    Van: mpiscoso@gmail.com [mailto:bounce-mpiscosogmailcom@community.progress.com]
    Verzonden: maandag 21 november 2016 15:30
    Aan: TU.Rollbase@community.progress.com
    Onderwerp: RE: [Technical Users - Rollbase] Cloning a record
     
    Update from Progress Community
     

    I see.

    If my understanding is correct, you've already tried using a Create New Trigger + Data Map?

    If not, I suggest you try that -- it would take out all this code that you have. (suggestion from my original reply).

    If you have, then might I suggest that in your data map, leave the auto-number field as "Not Mapped" or "Default Value".

    It might solve your +1 number issue.

    Hope this helps.

    View online

     

    You received this notification because you subscribed to the forum.  To unsubscribe from only this thread, go here.

    Flag this post as spam/abuse.

     
  • Hello,
    I tried the suggestion, now the system responses bt saying: To many ids requested: 64254.
    The autonumber field cannot by changed (it says ‘autonumber’)
     
    The newely created order has al the needed relations, but the are all gone from the order that was cloned.
     
    ?!
     
    Doesn’t seem to work.
    Regards, Wim
     
    Van: mpiscoso@gmail.com [mailto:bounce-mpiscosogmailcom@community.progress.com]
    Verzonden: maandag 21 november 2016 15:33
    Aan: TU.Rollbase@community.progress.com
    Onderwerp: RE: [Technical Users - Rollbase] Cloning a record
     
    Update from Progress Community
     

    If all else fails, unfortunately, I think you'd have to abandon the cloneRecord() API and use the createRecord() API.

    I haven't used the cloneRecord() api myself because I've never encountered your auto-number issue when using create new record and data maps in the past.

    Please confirm if you've tried Create New Record (trigger type) + Data map.

    Hope this helps. 

    View online

     

    You received this notification because you subscribed to the forum.  To unsubscribe from only this thread, go here.

    Flag this post as spam/abuse.

     
  • At the end of the data map that you are using, there should be some checkboxes there that indicate cloning related records (as opposed to just moving them from the order that was cloned.

    Could you post a screenshot of your data map and the create new record trigger that you are using?

    Thanks

  • Van: mpiscoso@gmail.com [mailto:bounce-mpiscosogmailcom@community.progress.com]
    Verzonden: maandag 21 november 2016 16:03
    Aan: TU.Rollbase@community.progress.com
    Onderwerp: RE: [Technical Users - Rollbase] Cloning a record
     
    Update from Progress Community
     

    At the end of the data map that you are using, there should be some checkboxes there that indicate cloning related records (as opposed to just moving them from the order that was cloned.

    Could you post a screenshot of your data map and the create new record trigger that you are using?

    Thanks

    View online

     

    You received this notification because you subscribed to the forum.  To unsubscribe from only this thread, go here.

    Flag this post as spam/abuse.

     
  • Hello,
    With the settings send the cloning is ok, but all the related records are gone from the records that needs to be cloned.
    Doesn’t bring me any further unfortunately.
     
    Regards, Wim.
     
     
    Van: mpiscoso@gmail.com [mailto:bounce-mpiscosogmailcom@community.progress.com]
    Verzonden: maandag 21 november 2016 16:03
    Aan: TU.Rollbase@community.progress.com
    Onderwerp: RE: [Technical Users - Rollbase] Cloning a record
     
    Update from Progress Community
     

    At the end of the data map that you are using, there should be some checkboxes there that indicate cloning related records (as opposed to just moving them from the order that was cloned.

    Could you post a screenshot of your data map and the create new record trigger that you are using?

    Thanks

    View online

     

    You received this notification because you subscribed to the forum.  To unsubscribe from only this thread, go here.

    Flag this post as spam/abuse.

     
  • Are the related lookups mapped?

    I think the setting you need to change is on the three relationships.

    You could probably try setting the related lookups to "not mapped" or "default value" or to blank.

    I would assume that for the three lookups that are set to clone, the cloned records should be the ones that would show and not affect the originals.

    Hope this helps

  • Hello,
    I followed your suggestion bij setting the related lookups to “not mapped”.
    Now it works fine !!!
     
    Thanks a lot,
     
    Maybe i can ask one last question:
    During the cloning of the records of the orderline, the ‘orderlinea_quantity’ value should be the negative number of the original orderline quantity.
    Do you have any suggestion om how to do the approach on this?
     
    Regards, Wim
     
    Van: mpiscoso@gmail.com [mailto:bounce-mpiscosogmailcom@community.progress.com]
    Verzonden: maandag 21 november 2016 16:29
    Aan: TU.Rollbase@community.progress.com
    Onderwerp: RE: [Technical Users - Rollbase] Cloning a record
     
    Update from Progress Community
     

    Are the related lookups mapped?

    I think the setting you need to change is on the three relationships.

    You could probably try setting the related lookups to "not mapped" or "default value" or to blank.

    I would assume that for the three lookups that are set to clone, the cloned records should be the ones that would show and not affect the originals.

    Hope this helps

    View online

     

    You received this notification because you subscribed to the forum.  To unsubscribe from only this thread, go here.

    Flag this post as spam/abuse.

     
  • Assuming that the field is an integer or decimal field: Create a formula field.

    Inside of the formula field's script, use the original value * -1 as the return value.

    Then map the field in the data map instead of the original field.

    That should get you what you need.

    Hope that helps.

  • Hi,
    Formule field seems promising, however dat is on the orderline object and not on the order object.
     
    The order is mapped, thats ok, but do i need a mapping on orderline records also, and if so how can i call upon them while cloning th order object.
     
    Regards, Wim
     
    Van: mpiscoso@gmail.com [mailto:bounce-mpiscosogmailcom@community.progress.com]
    Verzonden: maandag 21 november 2016 17:06
    Aan: TU.Rollbase@community.progress.com
    Onderwerp: RE: [Technical Users - Rollbase] Cloning a record
     
    Update from Progress Community
     

    Assuming that the field is an integer or decimal field: Create a formula field.

    Inside of the formula field's script, use the original value * -1 as the return value.

    Then map the field in the data map instead of the original field.

    That should get you what you need.

    Hope that helps.

    View online

     

    You received this notification because you subscribed to the forum.  To unsubscribe from only this thread, go here.

    Flag this post as spam/abuse.

     
  • Ah, I see what you mean now, the change needs to happen on the children and not the parent.

    1. On the child object, create a update field value trigger without any timing that changes the value that you need to change. (e.g. change qty to negative)

    2. On the parent object, create a "run triggers on related records" trigger without any timing - choose your child object in the picklist. Attach this trigger to your workflow action so it runs only at the time the workflow is pressed (assuming you use a clone workflow action - if you are not, you need to be to use this method).

    2.1 If you aren't using a workflow action, you need to create a trigger that iterates through all of your child record and calls runTrigger() on each on them to run the trigger in #1 (i prefer the "run triggers on related records" approach since it is more streamlined and less prone to code issues unlike this one).

    Hope this helps.

  • Hello,
    I followed your suggestion, but the trigger is running on the orderlines of the order that i clone, and not on on the cloned order / orderlines
    So the trigger is not aware of that i first clone the order record (and from the mapping cloning the orderlines)
    The clone orderlines need to have an negative quantity.
     
    Regards, WIm
    Van: mpiscoso@gmail.com [mailto:bounce-mpiscosogmailcom@community.progress.com]
    Verzonden: maandag 21 november 2016 17:23
    Aan: TU.Rollbase@community.progress.com
    Onderwerp: RE: [Technical Users - Rollbase] Cloning a record
     
    Update from Progress Community
     

    Ah, I see what you mean now, the change needs to happen on the children and not the parent.

    1. On the child object, create a update field value trigger without any timing that changes the value that you need to change. (e.g. change qty to negative)

    2. On the parent object, create a "run triggers on related records" trigger without any timing - choose your child object in the picklist. Attach this trigger to your workflow action so it runs only at the time the workflow is pressed (assuming you use a clone workflow action - if you are not, you need to be to use this method).

    2.1 If you aren't using a workflow action, you need to create a trigger that iterates through all of your child record and calls runTrigger() on each on them to run the trigger in #1 (i prefer the "run triggers on related records" approach since it is more streamlined and less prone to code issues unlike this one).

    Hope this helps.

    View online

     

    You received this notification because you subscribed to the forum.  To unsubscribe from only this thread, go here.

    Flag this post as spam/abuse.