Clicking on Lookup value navigating you to a different page. Well no more! Control this behavior with the new addOnLookupTagClick function in 2020 Release preview 1

 

With every release of Dynamics 365, there is something always new for developers. In my last blog I explained about the enhancement in Xrm.WebApi.navigateTo method. Today we will discuss in detail about the new “addOnLookupTagClick” method introduced in Release wave 1, 2020.

So what does this function do? Actually it solves a long standing problem where clicking on a lookup value, it redirected to the lookup record form. A potential problem with this is the user would lose context of the record they are working on. But now this can be avoided. So let’s see how we can achieve the same.

For this demo I use the Account form, Parent Account (parentaccountid) field.

In the onload of the Account form, I add the below code.

Xrm.Page.getControl('parentcustomerid').addOnLookupTagClick(function(e){ 
e.getEventArgs().preventDefault(); // disable the default behavior which to open the lookup record. 
// get the lookup record value 
var lookupRecord = e.getEventArgs().getTagValue(); 
// get formContext 
var fc = e.getFormContext(); 
});

The two most important part of the code are already highlighted inside the function with comments. The first one is to prevent the default behavior which is navigating to the lookup record.

The next one is even more important which allows you to select the lookup record clicked. I used the developer tools to show you the format of data returned by function.

The final line of code is to get the form context.

So what actually we can achieve with this. Well a lot. You can open up the lookup record form in a dialog as I explained in my previous blog.

Or may be you can open up a webresource to show up anything. I mean anything that your customer need to want.

Debajit Dutta

(Dynamics MVP)

For consultation/ training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

 
 

Author: Debajit

I am a Dynamics CRM Most Valuable Professional (MVP) with 12 years of experience in Microsoft .NET Technologies and 9 years of dedicated experience in Microsoft Dynamics CRM. I have worked with companies like Microsoft, SanDisk, PwC, TMF Group and have extensive experience of implementing complex CRM solutions from both offshore and client side. Currently the face of XrmForYou.com with significant experience in delivering corporate training on Dynamics CRM and have already delivered multiple projects to client through XrmForYou.com Author of multiple tools on codeplex including the 'Role Based Views' and 'CRM-Sharepoint Metadata manager & Attachment Extractor' which are available for commercial use under XrmForYou.com For consulting/ training, drop me a note at info@xrmforyou.com or visit our website www.xrmforyou.com

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 )

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s