web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

JavaScript code for Parent-Child contacts on Subgrid

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Verified answer
    ashlega Profile Picture
    34,477 on at

    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>";

  • Community Member Profile Picture
    on at

    Alex

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

    Thank you for your help

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans