Microsoft Release 2020: Open Dialog on Lookup field click

Normally, we have observed that whenever a user clicks on any lookup field value. Then the CRM navigates the user to the lookup entity record page.

Today’s we will learn how to stop user from navigating from one page to another page on click of lookup field value. This will help users to have a good experience while using CRM product and increase their productivity on their day to day activity on CRM.
This, will actually reduce the number of click which users makes while navigating from one entity to another entity main form and coming bank again to the main form page.

Let’s take an example of Account entity, when a user go to account entity they may have multiple lookup fields on the Account Main form. Clicking on the lookup field value user gets redirected to the lookup associated entity record. Today’s blog is related to the same scenario where when a user clicks on lookup field value, a dialog should open on the same main form instead navigating the user to another entity main form.

Steps to implement the Lookup dialog functionality and let’s take an example of Account entity.

  • Create a new Javascript web resource.
  • Add the web resource under Account Form libraries.
  • Then call the web resource function (LookupDialog) on the Account entity Form: OnLoad event.
  • Publish the changes.

Below is the code which you can use for achieving lookup dialog functionality. I have made it generic so that the same code can be used for any entity main form OnLoad event.

This feature is achievable with the help of OnLookupTagClick Event.

//Call function onload of form with execution context passed.
function LookupDialog(executionContext)
{
var formContext = executionContext.getFormContext();
//Get all attributes on form on event.
formContext.data.entity.attributes.forEach(function (attribute, index)
{
//For each attribute check whether the attribute type is "lookup" or not.
var attributeType = attribute.getAttributeType();
if(attributeType=="lookup"){
var attrName=attribute.getName();
//If attribute is of lookup type, add OnLookupTagClick event to field
OpenLookupDialog(formContext,attrName);
}
});
}

function OpenLookupDialog(formContext,lookupField)
{
formContext.getControl(lookupField).addOnLookupTagClick(context => {
context.getEventArgs().preventDefault();
const lookupTagValue = context.getEventArgs().getTagValue();
Xrm.Navigation.navigateTo(
{
pageType: "entityrecord",
entityName: lookupTagValue.entityType,
formType: 2,
entityId: lookupTagValue.id
},
{
target: 2,
position: 1,
width: {
value: 70,
unit: "%"
}
});
});
}
Figure 1: Adding Web resource on entity OnLoad event

Post publish –> Go back to the Account entity UCI form and refresh the page.

Figure 2: User click on Primary Contact which is a lookup field.
Figure 3: Contact main form opened on top of Account form.

Now, we have managed to stop the CRM from redirecting us to the lookup record page. Indeed we get the dialog on top of the page we were residing.

We also get the ability to maximize the dialog width to full screen. The option appear in the above picture under the green box. Once the dialog is maximized to to full screen we will still have the “X” icon on the screen. It will allow us to come back directly to the Account main form.

Note: This feature would work only on the UCI form not on Classic form.

Happy CRM! 😊

Create your website with WordPress.com
Get started
%d bloggers like this: