Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
716 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 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...