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

  • Expenses in PSA for Fixed Bid and T&M contracts

    23 August’ 2019

    Problem Definition: One of my clients decided to use Expense module in PSA and to his surprise he could see the amount v...

    Read more
  • Setup Dockers

    23 August’ 2019

    Docker is an independent container platform that enables organizations to seamlessly build, share and run any applicatio...

    Read more
  • Qualify Lead in D365 CE: Select which entity records should be created

    20 August’ 2019

    Wave 2019 Updates brought some really sought-after features. Another one which I would like to bring up is the Lead Qual...

    Read more
  • Early Opt-in for October 2019 Wave 2 Updates

    20 August’ 2019

    August 2, 2019 was when the Wave 2 Updates were to be out. And here we are! By now, you should have gotten the option to...

    Read more
  • Setting Unified Interface App Icons

    20 August’ 2019

    Default App Icons for typical D365 environment look like these.But here’s what you can do to change these to put...

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