Disable lookupfield links 

Disable lookup field links :

Sometimes will get the requirement to disable the lookup fields hyperlinks.

Pass the lookup field schema names with comma separated to the below function on Form Onload. It will disable the hyperlinks.

Note: This is MS unsupported code, but still it works.

// Pass multiple lookup field schemanames with comma separated.
function DisableLookupLinks(lookfieldname) {
try {
var res = lookfieldname.split(',');
for (var i = 0; i < res.length; i++) {
if (Xrm.Page.getAttribute(res[i]) != null && Xrm.Page.getAttribute(res[i]) != undefined) {
var lookupParentNode = document.getElementById(res[i] + "_d");
var lookupSpanNodes = lookupParentNode.getElementsByTagName("SPAN");
for (var spanIndex = 0; spanIndex < lookupSpanNodes.length; spanIndex++) {
var currentSpan = lookupSpanNodes[spanIndex];
currentSpan.style.textDecoration = "none";
currentSpan.style.color = "#000000";
currentSpan.onclick = function () { };
}
}
}
}
catch (ex) {
alert("Exception from DisableLookupLinks" + ex.message);
}
}

 

That’s It. Enjoy 🙂

Leave a comment