25 Dec’18

D365 GeneralFilter Customer Type field to display only Accounts in D365 V9.0 using JavaScript

Introduction:

In this blog we will see how to filter customer type field in Dynamics 365 to only show Accounts/Contacts dropdown.

Implementation:

Step 1: For demonstration purpose we will filter to only show Accounts. In the below image we can see that we have  a Customer type field which allows to choose from Contacts as well as Accounts.

Note: Here accounts are called as Companies.

Step 2: To display only Companies in the dropdown we register an event on Form Load.

Here we are working on the Contacts form, hence we first write a JavaScript code to filter the lookup to show only companies. Below shown in the code:

Code:

var oContactFormCustomization = {

setCustomerLookupToShowCompany: function (execContext) {

var formContext = execContext.getFormContext();
if (formContext.getControl("parentcustomerid")) {
var company = formContext.getControl('parentcustomerid');

if (company.getEntityTypes().length > 1) {
company.setEntityTypes(['account']);
}
}
}};

We add this script in CRM JS Web resource and add the library on the Contact form Properties

Form Properties

Below shown is the Handler Properties

Handler Properties

Once this is done we can see when the form loads the scripts executes and we can now view only the Companies and not the Contacts

Company Lookup Only

Hope this helped!

Written by

Clinton D'Mello

Software Engineer

Leave a Reply

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

Want to streamline your business processes?

  • This field is for validation purposes and should be left unchanged.

Recent Articles

  • 3 Biggest all-time ERP Myths

    17 January’ 2019

    Introduction: In my personal experience over the years, whenever I dealt with business owners, directors, and CTOs in t...

    Read more
  • Create a Customer, Vendor, or Bank Account from a Contact

    16 January’ 2019

    Introduction: Companies want to record some of contacts as customers, vendors, or bank accounts. Creating a customer, v...

    Read more
  • Creating an Email activity in MS CRM through WebApi

    16 January’ 2019

    Introduction: This blog explains how to Create an Email activity in MS CRM through WebApi Request: Post URL:  <yo...

    Read more
  • Time entry using model driven PowerApps

    10 January’ 2019

    Introduction: Managers and employees need a good time entry application to record worked hours for billing, payroll, or...

    Read more
  • Formatting Address Data separated by delimiter in the single field

    10 January’ 2019

    Introduction: Whenever the a single field in NAV contains Name, Address and other values seperated by delimiter such as...

    Read more