Restricting the customer lookup

First off, I have tested this only in CRMOnline on 8.1.0 and so this might not work for you if you are are in older version. You can now easily restrict the default entity of the lookup, if it links to multiple types. e.g. customer lookup. The script below is for attribute of type “customer”, but you can follow a similar approach for “partylist” as well.

These new functions are undocumented, so they are technically unsupported. So, use this at your own risk. In the script below, I am restricting a field with schemaname “customerid” and of type “customer” to “contact” entity only.

JavaScript

var lookupData = Xrm.Page.getAttribute('customerid').getLookupDataAttribute();

//check if multiple type dropdowns enabled for this lookup and it is not a partylist. For partylist we might want to select an account and a contact
if (lookupData.getSupportedLookupTypes().length > 1
	 && !lookupData.getIsPartyList()
	 && lookupData.getSingleLookupTypeId() !== 2) {
	lookupData.setLookupTypes(['contact'])
}

Screenshots

LookupLookup Search Customer

You can use this script during form load and easily restrict the lookup type.

Advertisements

14 thoughts on “Restricting the customer lookup

  1. Thanks for posting this. When I use the Customer field on the opportunity form I usually want it to refer to the Account, and it annoys me that when I type the account name it returns all the contacts at the account. This solution will make it easier to restrict the results to just accounts when needed.

  2. Hi, get an error when applying this to CRM Online 2016 Case form. Object doesn’t support property or method ‘getLookupDataAttribute’

    Please advise

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s