Opening Main Form Dialog from a lookup field using navigateTo and OnLookupClickTag method
With the 2020 Release Wave 1 update, a new method was introduced to open a new or existing record in a Main Form Dialog. There is an existing blog post from our Product Group that introduced the feature HERE, as well as details in our Docs site HERE. Since it is already covered there, I won’t go into the details of the method itself.
One example I did not see, was how you could do this from the click event of a lookup field. For example, there are many times it would be nice to open the record from a lookup field for a quick reference or overview of the record, without actually leaving the form you are on. It wasn’t too long ago that this wasn’t possible. Now, you can do this by using the OnLookupClickTag event documented HERE
Using a very simple example, I did this to the Regarding field of the Task form below
function taskLookupModalDialog(executionContext){ regardingLookup(executionContext); } function regardingLookup(executionContext){ formContext = executionContext.getFormContext(); formContext.getControl('regardingobjectid').addOnLookupTagClick(context => { context.getEventArgs().preventDefault(); const tagValue = context.getEventArgs().getTagValue(); Xrm.Navigation.navigateTo({ pageType: "entityrecord", entityName: tagValue.entityType, formType: 2, entityId: tagValue.id }, { target: 2, position: 1, width: { value: 80, unit: "%" } }); }) }
This event is added as an OnLoad event to the form where the lookup field exists.
;
Now, when you click on the Regarding field on the Task form, the record opens in a Dialog instead of navigating away from the Task form.
Thanks for reading!
Aaron Richards