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