How to disable hyperlink property of a lookup in dynamics crm (Unsupported way)

How to disable opening of record on click on the lookup in ms crm

This, a little weird requirement of disabling the hyperlink property of a lookup field in dynamic crm can be fulfilled with below code.

function DisableLookupHyperLink(lookupfieldname) 
{
 var lookupSpanNodes = document.getElementById(lookupfieldname + "_d").getElementsByTagName("SPAN");
 for (var spanIndex = 0; spanIndex < lookupSpanNodes.length; spanIndex ++) 
 {
 var getspan = lookupSpanNodes[spanIndex];
 getspan.style.textDecoration = "none";
 getspan.style.color = "#000000";
 getspan.onclick = function() {};
 }
}

Result is below:-

22.PNG

Call the above function on load of the form. Also if you want to keep the lookup disabled even after updating the lookup value, call on change of lookup as well.

Work like a charm in D365v9 as well.

Disclaimer:- Accessing and manipulating Dom is highly unsupported and not recommended. Please use at your own risk. May break anytime in future.

Happy CRMing…!!!

 

4 thoughts on “How to disable hyperlink property of a lookup in dynamics crm (Unsupported way)

Add yours

  1. I think a better, supported option would be to not even show the lookup, use script to populate a text field and did play that. make a ribbon button open a web resource to populate the lookup if the user needs to change the value.

    Liked by 1 person

    1. Absolutely, this post is just about this way, in some rare case when customer wants that end user shouldn’t be able to navigate to any lookup on record, making multiple text fields isn’t a good solution either(although supported). As disclaimer the way in this post is unsupported and should be used when no option left.

      Like

Leave a reply to Sagar Cancel reply

Blog at WordPress.com.

Up ↑