Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
712 views
in Technique[技术] by (71.8m points)

javascript - Set the Lookup field to show only Contacts

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...