Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

JavaScript code for Parent-Child contacts on Subgrid

Posted on by Microsoft Employee

Hello everyone!

We recently followed this article and successfully enabled the subgrid.  However, we have a couple of issues and was hoping someone familiar with JavaScript could help out;

  • The subgrid is pulling Active and Inactive contacts.  What would I add to the JS code to filter the results and only display Active contacts only?  I have tried changing the subgrid view in the Form Customization, but it looks like the JS code overwrites this upon loading.
  • Not sure if this can be fixed (and it's not a huge issue), but we're receiving a generic error message when we use the "plus" sign of the subgrid to add a new contact.  I have pasted the error below, error code 2147220989.  This error doesn't prevent the contact from being created.

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Expected non-empty string.Detail:

<OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">

  <ErrorCode>-2147220989</ErrorCode>

  <ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />

  <Message>Expected non-empty string.</Message>

  <Timestamp>2017-05-03T16:02:49.648248Z</Timestamp>

  <InnerFault i:nil="true" />

  <TraceText i:nil="true" />

</OrganizationServiceFault>

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: JavaScript code for Parent-Child contacts on Subgrid

    Alex

    Worked like a charm.  I'm aware this is unsupported, but it was a business need.

    Thank you for your help

  • Verified answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: JavaScript code for Parent-Child contacts on Subgrid

    Hi Pete,

     you know that customization is probably not "supported", right? That said, here is how that FetchXML should look like to only return "active" contacts:

    var fetchXml = "<fetch version='1.0' mapping='logical'>";
    fetchXml += "<entity name='contact'>";
    fetchXml += "<attribute name='fullname'/>";
    fetchXml += "<attribute name='emailaddress1'/>";
    fetchXml += "<order attribute='fullname' descending='false' />";
    fetchXml += "<filter type='and'>";
    fetchXml += "<condition attribute='statecode' operator='eq' value='0' />";
    fetchXml += "</filter>";
    fetchXml += "<link-entity name='account' from='accountid' to='parentcustomerid' link-type='inner' >";
    fetchXml += "<filter type='and'>";
    fetchXml += "<condition attribute='accountid' operator='eq-or-under' value='" + rootAccountID + "' />";
    fetchXml += "<condition attribute='accountid' operator='not-null' />";
    fetchXml += "</filter>";
    fetchXml += "</link-entity>";
    fetchXml += "</entity>";
    fetchXml += "</fetch>";

    Not sure what to do with the second error - since it's an unsupported customization, I'm guessing it's missing something.. But try adding contactid to the fetch.. like this:

    var fetchXml = "<fetch version='1.0' mapping='logical'>";
    fetchXml += "<entity name='contact'>";

    fetchXml += "<attribute name='contactid'/>";
    fetchXml += "<attribute name='fullname'/>";
    fetchXml += "<attribute name='emailaddress1'/>";
    fetchXml += "<order attribute='fullname' descending='false' />";
    fetchXml += "<filter type='and'>";
    fetchXml += "<condition attribute='statecode' operator='eq' value='0' />";
    fetchXml += "</filter>";
    fetchXml += "<link-entity name='account' from='accountid' to='parentcustomerid' link-type='inner' >";
    fetchXml += "<filter type='and'>";
    fetchXml += "<condition attribute='accountid' operator='eq-or-under' value='" + rootAccountID + "' />";
    fetchXml += "<condition attribute='accountid' operator='not-null' />";
    fetchXml += "</filter>";
    fetchXml += "</link-entity>";
    fetchXml += "</entity>";
    fetchXml += "</fetch>";

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans