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 () { };
    }
}

Advertisements

One thought on “Disable lookup hyperlinks on form using JavaScript in Dynamics CRM 2011

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s