Filter the Polymorphic Lookup – Regarding with a selected entity type
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:
- 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!