We got into a scenario were customer don’t want Email “To” field to have all entity and restrict “To” field with contact, Lead and User Entity Only
There was the same scenario for the customer which occurred last year and below was the code written fo that but the same javascript didn’t work multiple entity lookup for more than 2 entities
The old way of filtering Lookup for customer field JavaScriptÂ
function defaultlookfor(){ function addFilter(){ } |
For Multi entity lookup like Email entity TO, FROM, CC field or regarding field Below OOB JAVASCRIPT Works perfectly
JavaScript (9.x) – Supported
var lookupTO = Xrm.Page.getControl( 'to' ); //check if multiple type dropdowns enabled for this lookup if (lookupTo.getEntityTypes().length > 1) { Â Â Â Â lookupTO.setEntityTypes([ 'contact','lead','systemuser' ]); } |
JavaScript (8.x) – Unsupported
var lookupTO = Xrm.Page.getAttribute( 'to' ); //check if multiple type dropdowns enabled for this lookup  if (lookupTO.getLookupTypes().length > 1 && !lookupTO.getIsPartyList()) { lookup.setLookupTypes([ 'contact' ]); } |
We can Set above snippet onLoad of form ,
Remember in FormContext.getControl(arg).setEntityTypes([entityLogicalNames]); , entityLogicalNames is of array type and can have multple entities defined with comma.
Parameter entityLogicalNames
Name | Type | Required | Description |
---|---|---|---|
entityLogicalNames | Array of String | Yes | Specify the logical name of the entities allowed in the lookup control. |
Below is the lookup screenshot after restricting email “TO” field entities
function onFormRestrictEntity(executionContext) { var formContext = executionContext.getFormContext(); var if (lookupTO.getEntityTypes().length > 1 ) { lookup.setEntityTypes(['contact','lead','systemuser','queue'] ); } |