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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to filter lookup based on 2 criteria

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Suggested answer
    Charles Abi Khirs Profile Picture
    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

  • Suggested answer
    a33ik Profile Picture
    84,331 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

  • Community Member Profile Picture
    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?

  • Community Member Profile Picture
    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?

  • Martin Donnelly Profile Picture
    1,030 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.

  • Suggested answer
    Martin Donnelly Profile Picture
    1,030 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

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans