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 Contact Field in custom entity based on Custom fields in Account Entity .

(0) ShareShare
ReportReport
Posted on by

I have added 5 custom fields (Consultant 1,Consultant 2,Consultant 3,Consultant 4,Consultant 5 )(all Contact Type) in Account entity . also created a custom entity e.g. Support Entity . Support Entity has 2 fields "Account LookUp" and "Contact LookUp" . When user selects any account using "Account LookUp" field , all the consultant related to that account should be filtered /shown in "Contact LookUp". Is there any way to do this ? by configuration or by programming ? Any suggestion will be helpful .

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at
    RE: How to filter Contact Field in custom entity based on Custom fields in Account Entity .

    Thanks guys for your valuable help .

  • Suggested answer
    Arpit Shrivastava Profile Picture
    7,518 User Group Leader on at
    RE: How to filter Contact Field in custom entity based on Custom fields in Account Entity .

    Hi Rohit,

    Is there any specific reason for having 5 contacts lookup fields to keep consultant information on Account entity? if, in future consultants increase how would you handle that? In this case, every time you will have to create a new consultant field of contact type. Is it not?

    So can't you let the Account and Contact relationship as is and keep one 'Contact Type' field on Contact entity in order to distinguish who is Consultant and who is not. And 'Account' field is already there to associate the contact with the Account record.

    If you go this way the OOB Lookup filtering will work without doing any customization.

    And if you still want to continue with as is behavior then I don't think there is any way except the Custom Lookup Filtering.

    https://community.dynamics.com/crm/b/magnetismsolutionscrmblog/archive/2013/09/30/crm-2013-javascript-lookup-filtering-using-addcustomfilter

    https://community.dynamics.com/crm/b/powerxrmblog/archive/2016/06/13/lookup-filtering-using-addcustomview


    If found useful, please mark the answer as verified.


    Cheers
    Arpit
    https://arpitmscrmhunt.blogspot.com

     

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: How to filter Contact Field in custom entity based on Custom fields in Account Entity .

    Hi ,

    Please refer below article  -

    www.powerobjects.com/.../how-to-use-dependent-lookups-for-dynamics-crm-201320152016;utm_medium=feed&utm_campaign=Feed%3A+PowerobjectsMicrosoftCrmBlog+%28PowerObjects+Microsoft+CRM+Blog%29

    Also you can refer my video -

    www.youtube.com/watch

    Hope this helps.

  • Verified answer
    Shahbaaz Ansari Profile Picture
    6,211 on at
    RE: How to filter Contact Field in custom entity based on Custom fields in Account Entity .

    Hi Rohit,

    First get all the consultant on on change of account lookup in custom entity using below code, keep it on change of account

    ***********************************

    var consultant1;

    var consultant2;

    function getAllConsultant() {

    var accountid = Xrm.Page.getAttribute("accountlookupschemaname").getValue()[0].id;

    var consultantFetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+

    "  <entity name='account'>"+

    "    <attribute name='consultant1' />"+

    "    <attribute name='consultant2' />"+

    "    <attribute name='consultant3' />"+

     "    <attribute name='consultant4' />"+

      "    <attribute name='consultant5' />"+

    "    <filter type='and'>"+

    "      <condition attribute='accountid' operator='eq' value="+accountid+" />"+

    "    </filter>"+

    "  </entity>"+

    "</fetch>";

    var ConsultantRecords = XrmServiceToolkit.Soap.Fetch(consultantFetchXML);

    if (ConsultantRecords.length > 0) {

    if (ConsultantRecords[0].attributes.consultant1 != undefined)

    consultant1 = ConsultantRecords[0].attributes.consultant1;

     }

     if (ConsultantRecords[0].attributes.consultant2 != undefined)

    consultant2 = ConsultantRecords[0].attributes.consultant2;

     }

    preFilterlookup ();

    }

    *********************************

    get all the consultant id and pass it in below function addLookupFilter,

    Note : call preFilterlookup in above code when you get all the consultant value.

    **************************************************

    function preFilterLookup() {  

    Xrm.Page.getControl("contactlookup").addPreSearch(function () {

        addLookupFilter();

      });

    }

    function addLookupFilter() {

       if (email != null) {

           fetchXml = "<filter type='and'><condition attribute='contactid' operator='eq' value='" + consultant1 + "' /><condition attribute='contactid' operator='eq' value='" + consultant2 + "' /></filter>";

    Xrm.Page.getControl("contactlookup").addCustomFilter(fetchXml);

       }

    }

    **************************************************

    I have not tested it, Please debug the code and test it at your end.

    Hope this helps.

    Best Regards,

    Shahbaaz

  • Community Member Profile Picture
    on at
    RE: How to filter Contact Field in custom entity based on Custom fields in Account Entity .

    Unfortunatelly there is no out of the box way of achieving this, but You can use Javascript for this requirement.

    There is addPreSearch function on lookup field in witch You just have to setup custom fetchXML for filtering the contact Lookup to show only values form the consultant fields from dependent Account revord

    lookupControl.addPreSearch(function () {

    lookupControl.addCustomFilter(filterXML, entityName);
    });

    msdn.microsoft.com/.../gg334266.aspx

  • Suggested answer
    Michel van den Brink Profile Picture
    4,697 on at
    RE: How to filter Contact Field in custom entity based on Custom fields in Account Entity .

    Hello,

    The relationship is in the wrong direction for that. You'll need a 1:N relationship (one account, many contacts), rather than a N:1, which you've created.

    Dynamics 365 already comes with such a relationship between Account and Contact out-of-the-box, via the 'Account Name' field on 'Contact'. if you enter the same Account on those 5 different consultant Contact records, you can use this relationship to filter your lookup.

      

    Here's how to configure that on the 'Contact' lookup on your custom entity. I've taken the Case entity as an example but, it works the same for any entity.

    3276.dyncomm_5F00_mindsunited_5F00_contactlookuprelationaccount.png

      

    If you need those Contacts to be related to multiple Accounts, you will need an additional entity or a many-to-many relationship instead.

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#2
Christoph Pock Profile Picture

Christoph Pock 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans