Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

CRM 2016 Composite Attributes not Working in Clone Record Operation

Posted on by 924

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

  • Steve Le Monnier Profile Picture
    Steve Le Monnier 924 on at
    RE: CRM 2016 Composite Attributes not Working in Clone Record Operation

    Hi Andrew

    That worked beautifully, in fact I preferred your object based structure to my string arrays that I ripped my code out and switched it over to the style you've used. I did have some property names that needed to be dynamically added to the structure, but I've worked that out.

    Many thanks for your time, the finally solution was easy and I'm frustrated I wasted so much time doing down the wrong road.

    Cheers

    Steve

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CRM 2016 Composite Attributes not Working in Clone Record Operation

    Hi Steve,

    thanks for your feedback, if you need further help do not hesitate to ask.

    If you solved the problem or received help from an answer, please mark it as verified to encourage the community to provide more and more a better support.

    Thank you.

    Francesco

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna+Milano, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: CRM 2016 Composite Attributes not Working in Clone Record Operation

    Steve,

    Try following - it worked fine for me (no need to click to see full address in composite field):

    var p = {

    shipto_line1: Xrm.Page.getAttribute("shipto_line1").getValue(),

    shipto_composite: Xrm.Page.getAttribute("shipto_composite").getValue()

    };

    Xrm.Utility.openEntityForm("salesorder", null, p);

  • Steve Le Monnier Profile Picture
    Steve Le Monnier 924 on at
    RE: CRM 2016 Composite Attributes not Working in Clone Record Operation

    Hi Francesco & Andrew

    Many thanks for your efforts. I'm definitely closer to a solution than I was yesterday.

    I think the control vs attribute issue frist sent me down this link composite rabbit hole.

    It turns our you're both right:

    //parameters["shipto_composite_compositionLinkControl_shipto_line1"] = Xrm.Page.getAttribute("shipto_line1").getValue();

    parameters["shipto_line1"] = Xrm.Page.getAttribute("shipto_line1").getValue();

    This simpler version using just the attribute name works without errors.

    The only issue I've noticed is that one the new loaded record the composite address shows nothing, but when you click it the full address appears in the fly out menu.

    I'm hoping the composite attribute value can be copied the same way, I'll let you know when I discover.

    Many thanks for your assistance.

    Steve

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CRM 2016 Composite Attributes not Working in Clone Record Operation

    Hi Steve,

    I quote Andrii answer: if parameter refers to this function you need to use field name only, so shipto_line1.

    Please let us know.

    Francesco

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna+Milano, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: CRM 2016 Composite Attributes not Working in Clone Record Operation

    Steve,

    Error occurs because validation of parameters you can pass into form through url. Valid parameters are fields and field lookup names/types for a case with lookup fields and custom parameters you can configure (but again this is not your case). And in your particular case you don't have "shipto_composite_compositionLinkControl_shipto_line1" field. You have shipto_line1 field and you will have to use it if you want to pass data inside.

  • Steve Le Monnier Profile Picture
    Steve Le Monnier 924 on at
    RE: CRM 2016 Composite Attributes not Working in Clone Record Operation

    I've managed to get the address source data out using point 2. Xrm.Page.getAttribute("shipto_line1").getValue()

    However, loading into parameters and calling:

    Xrm.Utility.openEntityForm("salesorder", null, parameters);

    causes CRM form open to crash. See debug block below.

    I'm wondering if this is even possible or should I copy individual address lines, (but I think doing that will not set the composite)

  • Steve Le Monnier Profile Picture
    Steve Le Monnier 924 on at
    RE: CRM 2016 Composite Attributes not Working in Clone Record Operation

    Hi Francesco

    I've had a little bit more luck with your suggestion. I initial tried just "shipto_line1" but in the context of a control which it couldn't find. I didn't realise I could still refer to it as an attribute and acquire the value.

    Code has now been changed to : parameters["shipto_composite_compositionLinkControl_shipto_line1"] = Xrm.Page.getAttribute("shipto_line1").getValue();

    However, it is now crashing CRM when the new record loads. This is the info in the debug window:

    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: System.Web.HttpUnhandledException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #F354B187Detail:

    <OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance&quot; xmlns="schemas.microsoft.com/.../Contracts&quot;>

     <ErrorCode>-2147220970</ErrorCode>

     <ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic&quot;>

       <KeyValuePairOfstringanyType>

         <d2p1:key>CallStack</d2p1:key>

         <d2p1:value xmlns:d4p1="www.w3.org/.../XMLSchema&quot; i:type="d4p1:string">   at System.Web.UI.Page.HandleError(Exception e)

      at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

      at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

      at System.Web.UI.Page.ProcessRequest()

      at System.Web.UI.Page.ProcessRequest(HttpContext context)

      at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()

      at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)</d2p1:value>

       </KeyValuePairOfstringanyType>

     </ErrorDetails>

     <Message>System.Web.HttpUnhandledException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #F354B187</Message>

     <Timestamp>2018-01-31T13:53:02.3389812Z</Timestamp>

     <InnerFault>

       <ErrorCode>-2147220970</ErrorCode>

       <ErrorDetails xmlns:d3p1="schemas.datacontract.org/.../System.Collections.Generic&quot;>

         <KeyValuePairOfstringanyType>

           <d3p1:key>CallStack</d3p1:key>

           <d3p1:value xmlns:d5p1="www.w3.org/.../XMLSchema&quot; i:type="d5p1:string">   at Microsoft.Crm.Application.ParameterFilter.ValidateParameter(HttpRequest request, ArrayList parameterCollection, String key, String value, ParameterSources source, EntityType pageEntityType, FormAdditionalAllowedParameters additionalAllowedParameters)

      at Microsoft.Crm.Application.ParameterFilter.ValidateParameters(Page page, EntityType pageEntityType, Boolean alwaysEnableParameterChecking, FormAdditionalAllowedParameters formAdditionalAllowedParametersTemp)

      at Microsoft.Crm.Application.Controls.AppPage.ValidatePageParameters()

      at Microsoft.Crm.Application.Controls.AppPage.OnInit(EventArgs e)

      at System.Web.UI.Control.InitRecursive(Control namingContainer)

      at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)</d3p1:value>

         </KeyValuePairOfstringanyType>

       </ErrorDetails>

       <Message>System.InvalidOperationException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #EB0C993E</Message>

       <Timestamp>2018-01-31T13:53:02.3389812Z</Timestamp>

       <InnerFault i:nil="true" />

       <TraceText i:nil="true" />

     </InnerFault>

     <TraceText i:nil="true" />

    </OrganizationServiceFault>

    Have you or anybody else actually got this to work, I'm just wondering if I'm on a non-starter and need to find other ways of cloning a record containing addresses.

    Cheers

    Steve

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CRM 2016 Composite Attributes not Working in Clone Record Operation

    Hi Steve,

    please use the following code:

    parameters["shipto_composite_compositionLinkControl_shipto_line1"] = Xrm.Page.getAttribute("shipto_line1").getValue();

    This is the right syntax: dont use getControl, use getAttribute.

    Just do it.

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna+Milano, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: CRM 2016 Composite Attributes not Working in Clone Record Operation

    Steve,

    Here are several ideas why your code doesn't work:

    1. Name of attribute you want to populate should match schema field name i.e. shipto_line1.

    2. Xrm.Page.getControl("shipto_composite_compositionLinkControl_shipto_line1") returns control object but not the value of attribute. It should work like Xrm.Page.getAttribute("shipto_line1").getValue() but if you anyway want to use this control/attribute combo you should use Xrm.Page.getControl("shipto_composite_compositionLinkControl_shipto_line1").getAttribute().getValue()

    Good luck.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans