Filter the Polymorphic Lookup – Regarding with a selected entity type

Date:

DESCRIPTION

The “Regarding” polymorphic lookup field (logical name – “regardingobjectid”) is perhaps the most complex lookup in Dynamics 365. The reason it is referred to as polymorphic is – it looks up to many parent entities. We generally make use of it on Activity Entities (Email, Phone call, Appointment, etc.) in order to relate records with Accounts, Cases, Contacts, Users, Opportunities, Leads, etc.

In this blog, we will develop a quick mechanism to filter the “Regarding” dropdown to show only the records of a selected entity type as per the requirement.  

Steps:

  1. Login to your D365 CE instance and add a new option-set/choice column – Regarding Table Type to the Phone Call table.

2. The 2 local choices here are – Customer (1) and Case (2).

3 Create a new JavaScript web-resource and incorporate the following business logic of filtering entities in the “Regarding (regardingobjectid)” column based on the value selected in the column created above. Save and Publish.


// JavaScript source code
function filterRegarding (execContext)
{
	var formContext = execContext.getFormContext();
	if (formContext.getAttribute("qtq_regardingtabletype").getValue() != null)
	{
		regardingtype = formContext.getAttribute("qtq_regardingtabletype").getValue();
		if (regardingtype === 1) // Customer (Account & Contact)
		{
			formContext.getControl("regardingobjectid").setEntityTypes(["account", "contact"]);
		}
		else if (regardingtype === 2) // Case
		{
			formContext.getControl("regardingobjectid").setEntityTypes(["incident"]);
		}
	}
}

4 Add this JavaScript library on the Phone Call form and call the “filterRegarding” function on-change of Regarding Table Type. Save and Publish these changes.

Unit testing

  • Open a pre-existing Phone Call record, select Customer as the Regarding Table Type and verify if the Regarding lookup filters and shows just the Accounts & Contacts.

Likewise, select Case and check of the Regarding lookup filters to show only the cases in the drop-down.

Conclusion

Hence, in this blog, we successfully developed a quick mechanism to filter the “Regarding” Polymorphic Lookup based on our needs. Please do note that it can be implemented for Email, a CRM development company and Appointment D365 CE Tables too.

That’s all from this blog, see you in my next one! Take care!

 

TIME BUSINESS NEWS

JS Bin

Share post:

Popular

More like this
Related

Effective Skincare Tips for Glowing and Healthy Skin

Your skin is not only the largest organ of...

Rising Air Pollution in UAE – What can be done?

Air pollution is one of the famous problem that...

How Automotive Seat Manufacturers are Adapting to Electric and Autonomous Vehicles

The shift toward electric and autonomous vehicles is upending...

What to Know When Shopping for Jeep Wrangler Parts: A Friendly Guide

If you’re a Jeep Wrangler owner, chances are you...