Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Restrict Customer lookup on order form to populate contacts only

(0) ShareShare
ReportReport
Posted on by 3,618

I am using following code snippet to restrict Customer lookup on Order form to populate 'Contacts' automatically, it is working fine in CRM2016 but in D365 it automatically populate 'Accounts'.

Any suggestion to make customer lookup to show 'Contacts' automatically.

function defaultcustomer(){
	Xrm.Page.getControl("customerid").addPreSearch(addFilter);
}

function addFilter()
{
	var customerAccountFilter = "<filter type='and'><condition attribute='accountid' operator='null' /></filter>";
	Xrm.Page.getControl("customerid").addCustomFilter(customerAccountFilter, "account");
}


*This post is locked for comments

  • Community Member Profile Picture
    on at
    RE: Restrict Customer lookup on order form to populate contacts only

    Hi,

    in my case i had to restrict to accounts.. the filter is working 
    Is there any way can restrict the "new" button opens only to new account entity form.. default its opening new contact form

    2018_2D00_04_2D00_27_5F00_18_2D00_46_2D00_03.gif

  • donalmc Profile Picture
    123 on at
    RE: Restrict Customer lookup on order form to populate contacts only

    Thank you Jon!

    Just in case anyone else has my issue, I was trying to build a filter on the regardingobjectid field in an activity entity to return just accounts.

    I followed the steps you can find for the customerid field that means you have to exclude entity by entity.

    Jon's positive filter is much easier.

    Donal

  • Dynamics_Alok Profile Picture
    1,746 on at
    RE: Restrict Customer lookup on order form to populate contacts only

    Since you are calling addPreSearch ,you should call defaultcustomer on Load .It will register PreSearch and whenever you  click on lookup it will apply your Custom Filter.

  • Community Member Profile Picture
    on at
    RE: Restrict Customer lookup on order form to populate contacts only

    I would call this onload to restrict the lookup to contacts only

  • Mohsin Ali Profile Picture
    3,618 on at
    RE: Restrict Customer lookup on order form to populate contacts only

    At which event this will fire? on-change, onload?

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Restrict Customer lookup on order form to populate contacts only

    This should do the trick

    function defaultcustomer() {
      Xrm.Page.getControl("customerid").getAttribute().setLookupTypes(["contact"]);
    }

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans