1
votes

I have a lookup field which shows a lookup for 4 entities. So, I have added the PreSearch Filter to filter only the contacts when I click on the field. enter image description here But, when I click on Look for more Records, I want the search to be made only on Contacts entity.

I want to see only Contacts entity on the following image : enter image description here

Is it possible?

1
Was this resolved?Arun Vinoth

1 Answers

1
votes

It’s not possible to hide those related entities from the list. But we can disallow the users to choose any other unwanted entity records in that lookup.

We have to use addPreSearch and addCustomFilter. For example, to allow users to choose only contact but not account or systemuser, see the following snippet. This will filter out account & systemuser records from the view & users can move forward only by choosing contact.

    var contactFilter = "<filter type='and'><condition attribute='contactid' operator='not-null' /></filter>";
    //remove accounts
    var accountFilter = "<filter type='and'><condition attribute='accountid' operator='null' /></filter>";
    //remove system users
    var systemUserFilter = "<filter type='and'><condition attribute='systemuserid' operator='null' /></filter>";
Xrm.Page.getControl('requiredattendees').addCustomFilter(contactFilter, "contact");
Xrm.Page.getControl('requiredattendees').addCustomFilter(accountFilter, "account");    
Xrm.Page.getControl('requiredattendees').addCustomFilter(systemUserFilter, "systemuser");
        

Read more

Edit:

Adding another undocumented (hence unsupported) till 8.x

Xrm.Page.getAttribute('your_field').setLookupTypes(['contact']);

9.x documented & supported way:

Xrm.Page.getControl('your_field').setEntityTypes(['contact']);

Update: (replacement of above deprecated syntax)

function onFormLoad(executionContext) {
    var formContext = executionContext.getFormContext(); 
    formContext.getControl('your_field').setEntityTypes(['contact']);
}

Read more