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

  • Integrating Site24x7 into Microsoft Teams

    19 March’ 2019

    Introduction: Microsoft Teams is a cloud-based chat and collaboration platform, designed to simplify group work. It is...

    Read more
  • Manage and secure Dynamics 365 for Customer Engagement documents in SharePoint Online

    18 March’ 2019

    Introduction: When you check your Dynamics 365 Customer Engagement Entity records, you might think where your documents ...

    Read more
  • How to control the amount of information that is visible in a window in Business Central.

    18 March’ 2019

    Introduction: This blog demonstrates how the information that is visible to a user on the window can be controlled and m...

    Read more
  • PSA Quick Tip: Use Project instead of Project Template while creating a project in PSA V3

    15 March’ 2019

    Problem definition Often clients using PSA V2 used to complain of the feature missing was copying the project as the tem...

    Read more
  • Getting the price right post the time entries are approved in PSA

    15 March’ 2019

    PSA demands a perfect configuration and that is the proof of being a sophisticated application. You won’t see any resu...

    Read more