25 Dec’18

D365 General

Filter 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

  • How to enable Document ID in SharePoint Online

    16 May’ 2019

    Introduction: As you know that SharePoint Online can be used as a document management platform and with the help of Docu...

    Read more
  • Count Number of files in SharePoint folder

    15 May’ 2019

    Introduction: This blog explains how to Count No of files in SharePoint folder using MS Flow. Steps to be followed:Sel...

    Read more
  • Professional Services Automation (PSA) for CPA firms

    14 May’ 2019

    With the evolution of Technology, every industry is getting process oriented and so are CPA firms getting more organized...

    Read more
  • What if the Resource Requirement Still appears post the task is deleted from Schedule (WBS) in PSA V3?

    13 May’ 2019

    Problem Definition: I have observed a fact in PSA that when the task in PSA Schedule (WBS) is deleted, the corresponding...

    Read more
  • Discount Settings for D365 Sales Line Items – Line Items or Per Unit?

    10 May’ 2019

    For Line Item entities Opportunity Products, Quotes Products, Order Products or Invoice Products, you can chose what typ...

    Read more
  • We respect your privacy.
  • This field is for validation purposes and should be left unchanged.