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

I have the same question (0)
  • 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Varsha deshpande Profile Picture

Varsha deshpande 5

#2
NeerajPawar Profile Picture

NeerajPawar 2

#2
jlattimer Profile Picture

jlattimer 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans