Cloning a record

Posted by Wim on 21-Nov-2016 07:33

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

Posted by mpiscoso@gmail.com on 21-Nov-2016 07:55

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.

Posted by Wim on 21-Nov-2016 08:22
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.

 
Posted by mpiscoso@gmail.com on 21-Nov-2016 08:27

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.

Posted by mpiscoso@gmail.com on 21-Nov-2016 08:30

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. 

Posted by Wim on 21-Nov-2016 08:34
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.

 
Posted by Wim on 21-Nov-2016 08:54
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.

 
Posted by mpiscoso@gmail.com on 21-Nov-2016 09:00

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

Posted by Wim on 21-Nov-2016 09:18
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.

 
Posted by Wim on 21-Nov-2016 09:22
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.

 
Posted by mpiscoso@gmail.com on 21-Nov-2016 09:26

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

Posted by Wim on 21-Nov-2016 09:48
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.

 
Posted by mpiscoso@gmail.com on 21-Nov-2016 10:03

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.

Posted by Wim on 21-Nov-2016 10:14
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.

 
Posted by mpiscoso@gmail.com on 21-Nov-2016 10:21

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.

Posted by Wim on 21-Nov-2016 10:52
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.

 
Posted by mpiscoso@gmail.com on 21-Nov-2016 11:27

I see what you mean. For this I would suggest that you create a hierarchy relationship on your parent object and map it in your data map. Map it so that the cloned record would be the One in the one:many relationship, this way from the parent's perspective, you can access the token of the cloned record easily.

Then call your "run trigger on related records" on the related cloned record using runTrigger() API and possibly an object script appended to your workflow action (don't forget to remove the other trigger from the workflow).

This should make the trigger run on the cloned record.

Hope that helps.

Posted by Wim on 22-Nov-2016 04:06
Hi,
I managed following your suggestions as earlier mentioned:
Button on order page
Three triggers that are fired:

1.      Put negative values in orderline (quantity etc)

2.      Clone object order (which creates also orderlines (with negative values)

3.      Put negative value (which reverses point 1) so we have positive values in original orderline again.

Works great, thanks again, you have been a great help
 
Wim
 
Van: mpiscoso@gmail.com [mailto:bounce-mpiscosogmailcom@community.progress.com]
Verzonden: maandag 21 november 2016 18:29
Aan: TU.Rollbase@community.progress.com
Onderwerp: RE: [Technical Users - Rollbase] Cloning a record
 
Update from Progress Community
 

I see what you mean. For this I would suggest that you create a hierarchy relationship on your parent object and map it in your data map. Map it so that the cloned record would be the One in the one:many relationship, this way from the parent's perspective, you can access the token of the cloned record easily.

Then call your "run trigger on related records" on the related cloned record using runTrigger() API and possibly an object script appended to your workflow action (don't forget to remove the other trigger from the workflow).

This should make the trigger run on the cloned record.

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.

 
This thread is closed