Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to filter lookup based on 2 criteria

Posted on by Microsoft Employee

Hi,

We have a contact lookup on Account that we want to restrict to only display the contact linked to that Account OR that Account parent account

Is there a script that be can be done for this?

I can do just the former via the built in form field "related records filtering"

Thanks,
Jonathan

*This post is locked for comments

  • Suggested answer
    Martin Donnelly Profile Picture
    Martin Donnelly 1,010 on at
    RE: How to filter lookup based on 2 criteria

    PS- and you're going to have to change the setting of your lookup field on the form to NOT include only associated records -- I think

  • Martin Donnelly Profile Picture
    Martin Donnelly 1,010 on at
    RE: How to filter lookup based on 2 criteria

    Here's the xrm method for the javascript: docs.microsoft.com/.../addcustomview

    You're going to have to build your fetchXML in the script -- something like ... contact.parentAccountid IN><this accountid /><this parentaccountid /></filter>

    (very, very pseudo-script -- don't copy it literally) and follow Andrew's link above to inject it into the lookup view on the client side.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to filter lookup based on 2 criteria

    Thanks for the reply

    Doesn't that only allow you to define one contact? whereas we want to show all contacts linked to either the current OR parent contact

    Am I misreading it?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to filter lookup based on 2 criteria

    Thanks for the reply

    Potentially more than 2

    The Contact lookup field is on Account A.

    Account A has a parent account of Account B

    On the contact lookup field on Account A, we want to pre filter it to only give contacts where the account they are linked to is Account A OR Account B

    Is that clearer?

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: How to filter lookup based on 2 criteria

    Hello,

    You definitely can use the script - www.magnetismsolutions.com/.../crm-2013-javascript-lookup-filtering-using-addcustomfilter

  • Suggested answer
    Charles Abi Khirs Profile Picture
    Charles Abi Khirs 3,569 on at
    RE: How to filter lookup based on 2 criteria

    Hello,

    Just to clarify, in the contact lookup field you will have maximum 2 records (the one related to the current account and the other contact related to the parent account). Correct?

    If it is the case, you can use the function addCustomView as in this link: https://charlesak.blogspot.com/2019/03/crmd365-filter-lookup-based-on-nn.html

    Of course your fetchXml should be changed to meet your needs. You can use the Advanced Find to properly get your FetchXml

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans