Set the Lookup field to show only Contacts

自古美人都是妖i 提交于 2019-12-13 18:12:45

问题


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. 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 :

Is it possible?


回答1:


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



来源:https://stackoverflow.com/questions/50836891/set-the-lookup-field-to-show-only-contacts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!