Disable lookup hyperlinks on form using JavaScript in Dynamics CRM 2011

Use following JavaScript functions to disable lookup fields hyperlinks on Header, Body, Footer sections on any CRM form

Example method to disable Owner and Primary Contact fields on Header, PrimaryContact field on Body and CreatedBy,ModifiedBy fields on Footer on Account form

Call DisableLinks() in the account form load and include other methods in Account entity JavaScript file.
 

Before applying Script
Before

After applying Script
After


//disable Owner field on Header, Account field on Body and CreatedBy field on Footer
function DisableLinks() {
    DisableHeaderLinks("ownerid");
    DisableHeaderLinks("primarycontactid");
    DisableLookupLinks("primarycontactid");
    DisableFooterLinks("createdby");
    DisableFooterLinks("modifiedby");
}
//to disable Lookup hyderlinks
function DisableLookupLinks(lookupFieldName) {
    var lookupParentNode = document.getElementById(lookupFieldName + "_d");
    var lookupSpanNodes = lookupParentNode.getElementsByTagName("SPAN");

    for (var spanIndex = 0; spanIndex < lookupSpanNodes.length; spanIndex++) {
        var currentSpan = lookupSpanNodes[spanIndex];

        // Hide the hyperlink formatting
        currentSpan.style.textDecoration = "none";
        currentSpan.style.color = "#000000";

        // Revoke click functionality
        currentSpan.onclick = function () { };
    }
}
//to disable Footer hyperlinks
function DisableFooterLinks(lookupFieldName) {
    var lookupParentNode = document.getElementById("footer_" + lookupFieldName + "_d");
    var lookupSpanNodes = lookupParentNode.getElementsByTagName("SPAN");

    for (var spanIndex = 0; spanIndex < lookupSpanNodes.length; spanIndex++) {
        var currentSpan = lookupSpanNodes[spanIndex];

        // Hide the hyperlink formatting
        currentSpan.style.textDecoration = "none";
        currentSpan.style.color = "#000000";

        // Revoke click functionality
        currentSpan.onclick = function () { };
    }
}

//to disable Header hyperlinks
function DisableHeaderLinks(lookupFieldName) {
    var lookupParentNode = document.getElementById("header_" + lookupFieldName + "_d");
    var lookupSpanNodes = lookupParentNode.getElementsByTagName("SPAN");

    for (var spanIndex = 0; spanIndex < lookupSpanNodes.length; spanIndex++) {
        var currentSpan = lookupSpanNodes[spanIndex];

        // Hide the hyperlink formatting
        currentSpan.style.textDecoration = "none";
        currentSpan.style.color = "#000000";

        // Revoke click functionality
        currentSpan.onclick = function () { };
    }
}

3 thoughts on “Disable lookup hyperlinks on form using JavaScript in Dynamics CRM 2011

Leave a comment