Filtering the Customer Column in Dynamics 365 to Display Only Accounts or Contacts

 In Microsoft Dynamics 365, the customerid lookup field can reference multiple entity types, typically Accounts and Contacts. To simplify the user interface or meet specific business needs, you may want to restrict this lookup to show only one type. Below is a straightforward approach using JavaScript to configure the customerid lookup to display either only Accounts or only Contacts.

JavaScript Function to Display Only Accounts:

function filterCustomerToAccounts(executionContext)
{
    var formContext = executionContext.getFormContext();
    var customerLookup = formContext.getControl("customerid");
    if (customerLookup !== null)
    {
        customerLookup.setEntityTypes(["account"]);
    }
}

JavaScript Function to Display Only Contacts:

function filterCustomerToContacts(executionContext)
{
    var formContext = executionContext.getFormContext();
    var customerLookup = formContext.getControl("customerid");
    if (customerLookup !== null)
    {
        customerLookup.setEntityTypes(["contact"]);
    }
}

Implementing the Filter:

To implement this filter, add the relevant JavaScript function to your Dynamics 365 form properties and set it to trigger on form load. This configuration ensures that when a user interacts with the customerid field, they will see only the specified entity type, either Accounts or Contacts, based on the function you have attached.

This approach is efficient for scenarios where a specific type of data entry is required and helps maintain data integrity and user focus on relevant entities.

No comments:

Post a Comment