Skip to main content

Notifications

Announcements

No record found.

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

  • Suggested answer
    antc Profile Picture
    antc 2,909 on at
    RE: Filtered Lookup

    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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,820 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,514 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans