Uncategorized

{Model Driven App} dynamically change view on polymorphic/Multi table form field

In today’s blog, I will walk you through the process to show specific Entity view for Multi Table/Polymorphic lookup field based on another field value.

Multi table lookup is to create a lookup field in Dynamics crm which will point to multiple enities. More details can be found on below link –

I have a polymorphic lookup field which is pointing to Visit and Building Entity and Lets say we have a requirement to show Visit Entity only when Full Time Employee field value is Yes and Building Entity only when Full Time Employee is No.

To Achieve this requirement we can write below JS code and attach it on Onload of the form and Onchange of the Full Time Employee field

function onLoad(executionContext){
	formContext = executionContext.getFormContext();
	var isFTE=formContext.getControl("msft_isfulltimeemployee").getValue();
	alert("Full Time Employee"+isFTE);
	if(isFTE=="Yes")
	{
		alert(1);
	formContext.getControl("new_polymorphicfieldid").setEntityTypes(['bc_visit']);
	}
	else
	{
		alert(2);
	formContext.getControl("new_polymorphicfieldid").setEntityTypes(['bc_building']);
	}
}

Once you have published your changes and when you go to your form and open record, you will see Polymorphic lookup field Entity Type is getting changed dynamically based on the Full Time Employee field value –

Hope this helps!

Advertisement

One thought on “{Model Driven App} dynamically change view on polymorphic/Multi table form field

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s