Filter PartyList Field based on other lookup field that supports on UCI Dynamics 365 v9.x

By | November 16, 2018


Recently we had a business requirement where client wants to filter PartyList field by selected account in regarding field on activity entity form.

As shown in below image, when we click on party list field, by default it shows data of many entities (i.e. Account, Contact, and User etc.)

Filter PartyList Field based on other lookup field that supports on UCI Dynamics 365

Our client requirement is to filter PartyList field “Required Attendees” and show only Contact based on Account selected in “Regarding” field and that should be supported in UCI.

To achieve this we have developed JavaScript, which apply addPreSearch to PartyList field “Required Attendees”.

Here we used “addCustomFilter” function to apply custom condition and “setEntityTypes” function to set entity of contact type.

For reference please find JavaScript code as below:

function filterRequiredAttendees() {
    var functionName = "filterRequiredAttendees: ";
    try {

        // Get requiredattendees
        var regardingObject = Xrm.Page.getAttribute("regardingobjectid");

        // Validate regarding field
        if (!isValid(regardingObject))  {

        // Validate value of regardingObject
        if (regardingObject.getValue() == null) {

        // Get requiredattendees control
        var requiredAttendeesControl = Xrm.Page.getControl("requiredattendees");

        // Validate requiredattendees field
        if (isValid(requiredAttendeesControl)) {

            // Add PreSearch

            // Check if multiple type dropdowns enabled for this lookup
            if (requiredAttendeesControl.getEntityTypes().length >= 1) {

                // Set entity type to contact
    catch (e) { throwError(e, functionName); }

function filterContactByAccount() {

    var functionName = "filterContactByAccount: ";

    try {

        var regardingObjectValue = Xrm.Page.getAttribute("regardingobjectid").getValue();

        // Validate Regarding has a value
        if (regardingObjectValue != null) {

            // Get Account GUID
            var regardingID = regardingObjectValue[0].id;

            var filterCondition = "<filter type='and'>" + "<condition attribute='parentcustomerid' operator='eq' value='" + regardingID + "' />" + "</filter>";
            Xrm.Page.getControl("requiredattendees").addCustomFilter(filterCondition, "contact");

    catch (e) { throwError(e, functionName); }

Add this scripts as web resources, add these libraries to the activity entity form, then we have to set the Form Properties, set “filterRequiredAttendees” function “OnLoad” of the form, and “OnChange” of the “Regarding” field.

Deploy and publish the changes. Refresh (Ctr+F5) the activity entity form and we are good to filter partylist field.

Now PartyList field “Required Attendees”, shows only Contact based on Account selected in “Regarding” field.

Filter PartyList Field based on other lookup field that supports on UCI Dynamics 365


Using the “addPreSearch”, addCustomFilter”, and “setEntityTypes” functions we can filter PartyList fields that supports on UCI too.

Dynamics 365 for Customer Engagement apps version 9.x provided the following client APIs, which are not available in the previous versions.

1. getEntityTypes – Gets the types of entities allowed in the lookup control

Syntax: formContext.getControl(arg).getEntityTypes();

2. setEntityTypes – Sets the types of entities allowed in the lookup control.

Syntax: formContext.getControl(arg).setEntityTypes([entityLogicalNames]);


4 thoughts on “Filter PartyList Field based on other lookup field that supports on UCI Dynamics 365 v9.x

  1. Vaishali Aghera

    I have tried the same in my custom entity but customfilter is not working in UCI.
    Can you please help with this!!

    1. inogic Post author

      Could you please let us know the actual issue with an error message that you faced during this so that we can try to replicate it and provide you solution.


  2. shiva


    I have added 3 lookup types, for example [“contact”, “account”, “systemuser] and applied presearch and custom filter only Contact based on Account selected in “Regarding” field.(As explained in article)
    formContext.getControl(arg).setEntityTypes( [“contact”, “account”, “systemuser] );
    But default entity showing account instead contact. But If I select contact from the 3 entities, filter is applied.
    ****Problem: Default entity type is not showing contact.
    **But in Web Interface, deault entity type showing contact.

    1. Inogic Post author


      We have tried the same code in trial environment for ‘Appointment’ and ‘Phonecall’ activity entity and it is working as expected.

      When ‘Regarding’ field contains ‘Account’ entity then it displays related ‘Contact’ record in ‘Required Attendees’ lookup field as mentioned in the blog.

      It would be much better if you could provide more details on this so that we can help.

      We also have a query:
      Have you ever registered ‘filterRequiredAttendees’ function on onLoad event of the form as mentioned in the blog?



Leave a Reply

Your email address will not be published. Required fields are marked *