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:-
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…!!!
This is unsupported way. We should not do this.
LikeLike
yes it is. it should only be used when it’s the last option
LikeLike
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.
LikeLiked by 1 person
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.
LikeLike