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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Filtered Lookup

(0) ShareShare
ReportReport
Posted on by 2,911

Hi

I'm having trouble with the following.

On Account entity have a field thats a lookup for Account i.e. a service business(account) and a lookup service personnel(contacts).

I can't work out how to filter the service peronnel(contact) by contacts that have the service business(account) as their parent.

Filtered lookup OOB won't work I don't think as it is technically a lookup to the same entity.

I can't get my head around the fetch JS to do a filtered view for this scenario.

*This post is locked for comments

  • Suggested answer
    antc Profile Picture
    2,911 on at

    Oh it can be fustrating when somethings so simple.

    function servicePerson() {

       // add the event handler for PreSearch Event

       Xrm.Page.getControl("dsd_serviceperson").addPreSearch(addFilter);

    }

    function addFilter() {

    var entityId, lookupFieldObject;

    lookupFieldObject = Xrm.Page.data.entity.attributes.get('dsd_serviceaccount');

       if (lookupFieldObject.getValue() != null) {

           entityId = lookupFieldObject.getValue()[0].id;

       }

       if (entityId != null) {

       //create a filter xml

      var filter = "<filter type='and'>" +

                   "<condition attribute='parentcustomerid' operator='eq' value='" + entityId + "'/>" +

                    "</filter>";

       //add filter

       Xrm.Page.getControl("dsd_serviceperson").addCustomFilter(filter);

       }

    }

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
TNJ_CRM_Team Profile Picture

TNJ_CRM_Team 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans