Please wait, loading...

 

Restricting the Multi Entity lookup field Customer or Regarding Party list Entities from Email TO, CC, From – supported JavaScript on UCI Dynamics 365

May 21, 2020

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(){
Xrm.Page.getControl(“parentcustomerid”).addPreSearch(addFilter);
}

function addFilter(){
var emailToFilterAcc = “<filter type=’and’><condition attribute=’accountid’ operator=’null’ /></filter>”;
Xrm.Page.getControl(“to”).addCustomFilter(emailToFilter , “account”);

}

 

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

TABLE 1
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();
varlookupTO = formContext.getControl('to');
if (lookupTO.getEntityTypes().length > 1) {
lookup.setEntityTypes(['contact','lead','systemuser','queue']);
}

 

 

Reference : https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/controls/setEntityTypes

https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/04/Microsoftdynamics365.png?fit=640%2C651
Microsoft Dynamics Community Profile

Learn more