Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Restrict Customer lookup on order form to populate contacts only

Posted on by 3,610

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
    Community Member Microsoft Employee 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
    donalmc 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
    Dynamics_Alok 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
    Community Member Microsoft Employee 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
    Mohsin Ali 3,610 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
    Community Member Microsoft Employee 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

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,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans