Custom Lookup Filtering in ADX/CRM Portal

As we all know that, Microsoft has given us the exciting new feature of being able to simply apply a custom filter to a lookup itself, meaning ALL views available in the lookup are filtered. In addition to this, we have also been given the ability to apply this filter immediately as the lookup is clicked, rather than on load or on change of the related fields.

OOB Lookup filtering is supported on Adxstudio and CRM Portal same like CRM.

But in few scenarios we cannot use CRM OOB Lookup Filter, we have to move towards Custom Lookup filter in CRM. But what about Portal where XRM Model is not supported yet ?

Custom Lookup Filtering is not supported on CRM Portal, but today in this article I am going to share a way through which we can achieve the Custom Lookup Filtering on Portal as well.

I would like to take a example here –

Requirement – 

Suppose I am exposing Account Entity Form on Portal, On this form I have a field \’Primary Contact\’, Requirement is to filter \’Primary Contact\’ based on Logged In User Account.

You would be thinking, if Portal supports CRM OOB Lookup Filtering then why we can\’t achieve it through OOB Lookup Filtering by keeping one Custom Account Lookup on Account form and filtered Primary Contact based on that.

Yes, you are right i was also thinking the same, but hold on \”We cannot filtered record of any entity by keeping the lookup field of same entity\” For example. We cannot Filtered Contacts based on Account by keeping one Account Lookup filed on Account entity itself.

Hope you understood this limitation in CRM, that\’s why we thought of to do the Custom Lookup Filter on Portal.

This is one requirement, you might come across other requirement also which require something similar like this.

So here is the way –

Step 1 : First of all Convert Lookup into Dropdown on which you want to apply Custom Lookup Filter. This you can make it possible through Entity Form Metadata.

You can have a look this link for more informationConvert CRM Lookup to Dropdown in CRM Portal.

Step 2 : Keep \’Parent Account\’ field on Account form (if you are not using it already for other purpose),
Note – If you have been using this field for other purpose, you can create custom Account lookup field also.

Step 3 : Intention for keeping this field on Account Form is to auto-populate logged In User\’s Account in this field.
For this Create one Entity Form Metadata on \’Account Entity Form\’ which will auto populate account\’s name of logged In User\’s in that field.

You can have a look this link for more information > How to auto populate data on Entity Form

Step 4 : So now we are done with all pre-requisites, Now the intent is to filter the dropdown and remove all the options from dropdown which we needs to filtered out or which we don\’t wants to be shown in dropdown list.

Here is the code to achieve the same –

$(document).ready(function () {

    //First we will get the Logged In User\’s Account (on the basis of that we have to filter \’Primary Contact\’), which we have already stored on \’Parent Account\’ field using Entity Form Metadata. We kept this field only to get Logged In User\’s Account.
    // Get the Account Information (Guid) from that field
    var loggedInUserAccountGUID = $(\’#parentaccountid\’).val();

    // Get All accounts which does not belongs to logged in user\’s account
    var getContacts_FilteredOut = \”/_odata/contacts/?$filter=parentcustomerid/Id%20ne%20(guid%27\” + loggedInUserAccountGUID + \”%27)\”;

        type: \”GET\”,
        url: getContacts_FilteredOut,
        dataType: \’json\’
    }).done(function (json) {

        // Got accounts collection which are not associated with logged In user\’s account
        var contactsColl = json.value;

        $.each(contactsColl, function (index, con)
            // Remove these account from dropdown, so that only logged In user\’s account\’s contact will be rendered in dropdown
            if (con.contactid) {
                var contactGUID = con.contactid;

// We have removed the options instead of making it Hide, because IE browser does not support Hide/Show of dropdown options, We made it browser compatible.

                $(\”#primarycontactid option[value=\’\” + contactGUID + \”\’]\”).remove();


Hope this article helps you, Please share your feedback and feel free to get in touch with my for any query.


Published by arpitpowerguide

My name is Arpit Shrivastava, who is a Microsoft MVP in the Business Applications category. I am a Microsoft Dynamics 365 and Power Platform enthusiast person who is having a passion for researching and learning new things and acquiring immense knowledge. I am providing consistent help, support, and sharing my knowledge through various Social Media Channels along with my Personal Blog, Microsoft Community, conducting online training and attending various 365 Saturday Events worldwide and sharing the best Solutions to the readers helping them achieve their goals and objectives in Customer Relationship Space.

5 thoughts on “Custom Lookup Filtering in ADX/CRM Portal

  1. I have country and city dropdown…I used the same filter method you used on the change of country drop down …the city dropdown removes some records but shows some extra record which are not related to them


  2. Special thanks to ( for exposing my cheating husband. Right with me i got a lot of evidences and proofs that shows that my husband is a fuck boy and as well a cheater ranging from his text messages, call logs, whats-app messages, deleted messages and many more, All thanks to (, if not for him i will never know what has been going on for a long time. Contact him now and thank me later.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: