We are currently using CRM2016 and on the Sales Order entity we've added a CLONE button to the ribbon. This is to allow the users to clone the record to a new record but only some fields are transferred. Most importantly we want them to finish entering data on the new record, which is why we've gone with a JavaScript based solution and not workflow.
I've achieved this by making use of the method "xrm.Utility.openEntityForm("salesorder", null, parameters);". Where parameters is an array of attribute names and the value you wish to transfer across to the new record instance.
So far this is working well and I'm pleased with the results, that was until I started hitting problems with the new composite fields. In particular the address composites, which on the Sales Order form are “Ship To” and “Bill To”, both I wish to copy to the new record.
According to the Microsoft Documentation these composite fields can still be accessed via JavaScript:
You can access the individual constituent controls displayed in the flyout by name. These controls use the following naming convention: <composite control name>_compositionLinkControl_<constituent attribute name>. To access just the address_line1 control in the address1_composite control you would use: Xrm.Page.getControl("address1_composite_compositionLinkControl_address1_line1").
Within Sales Order the two composite controls for addresses are “shipto_composite” and “billto_composite”. However, I was not having much luck with the address1_line1 suffix for those controls. After digging around in the form editor I notice the fields may actually be call shipto_line1 and billto_line1 rather the traditional address_line1 we are used to seeing on accounts and contacts.
So I made the following code change:
parameters["shipto_composite_compositionLinkControl_shipto_line1"] = Xrm.Page.getControl("shipto_composite_compositionLinkControl_shipto_line1");
No more errors, but unfortunately no value either!
I’ve played around with the form debugger, but I cannot seem to find any values within the composite flyout controls that I can use in my script.
Q. Does anybody know what I’m doing wrong, or does this simply not work on Sales Order entities, and if that’s the case how do I copy the ShipTo and BillTo Address details to a new form via the "xrm.Utility.openEntityForm("salesorder", null, parameters);" method?
Any help gratefully received
Steve
*This post is locked for comments