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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Filtered Lookup

(0) ShareShare
ReportReport
Posted on by 2,909

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

I have the same question (0)
  • Suggested answer
    antc Profile Picture
    2,909 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

Responsible AI policies

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

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ZS-27011425-0 Profile Picture

ZS-27011425-0 1

#1
ZS-27011425-0 Profile Picture

ZS-27011425-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans