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

Notifications

Announcements

No record found.

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,634

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

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    This should do the trick

    function defaultcustomer() {
      Xrm.Page.getControl("customerid").getAttribute().setLookupTypes(["contact"]);
    }
  • Mohsin Ali Profile Picture
    3,634 on at

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

  • Community Member Profile Picture
    on at

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

  • Dynamics_Alok Profile Picture
    1,746 on at

    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.

  • donalmc Profile Picture
    125 on at

    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

  • Community Member Profile Picture
    on at

    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

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans