Wednesday, October 6, 2010

Disable the Links in a Lookup Field

[UPDATE: Thanks to Mad Computerist for his recommendations for script additions to remove hyperlink formatting!]

Sometimes simply making a Lookup field “read only” isn’t enough.  Sometimes, you may want to restrict the ability to even follow the links held inside the field.  Though it may be trivial to work around such a limitation, sometimes a dead-bolt keeps people out of your house by virtue of being a dead-bolt.  That said, here’s a handy function I whipped up to meet such a need:

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 = "none"; = "#000000";

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

To disable a field's Lookup links, pass the field's schema name into the function.  For example, for the "Customer" field on a Case:


The code also conveniently works for multi-record Lookup fields, such as party-lists on activity records.


  1. Your code was reposted without any reference to you, dear Dave. How I hate such reposting...

  2. Thanks for the tip, Andriy. I don't apply copyright to these minor script things, like I do to the Grid Editor. So, I'm much less concerned about anyone "stealing" it. However, it is bad form and distasteful to use something created by somebody else, and not credit them with it.

    I'm just glad to have friends like you who keep a watchful eye for those "bad actors."

  3. Maybe that person can't create something like how u do so he copy it and claim that it his work. you can see the date. Yours is 6 October and he posted at 7 october

  4. Dear Anonymous.

    This is for sure is copypasting.

  5. Andriy,

    It is obvious theat he copy and paste.

  6. Thanks for the function Dave....
    I added two more lines in my function as below to make the text not to look like a hyperlink. :)

    var currentSpan = lookupSpanNodes[spanIndex]; = "none"; = "#000000";

    currentSpan.onclick = function() {};

  7. Nice addition, Mad Computerist! It's definitely a good idea to mask the apparent functionality from the user when masking the true functionality. I'll roll your updates into the script a little bit later. Thanks for the contributions!

  8. Hi Dave,

    I'm in charge of my company's implementation of CRM 2011 and like to do as much of the customisation work myself as possible. I am studying to become a programmer in my spare time, but without a software development background and the right development tools it is often difficult to get seemingly simple changes to work as I would like. I've got to say a massive thanks for this post, I've successfully integrated your snippet into numerous CRM which has closed a loophole that threatened the security of our data. What's more I've taken another step away from merely "customising" our solution using the CMr front-end, to actually coding.

    Thanks a lot and keep up the good work!


  9. You're welcome, Ryan. It is a pleasure, and I thank you for such a kind note!

  10. hi.. i know your code will help me. but, where do i supposed to add the DisableLookupLinks("customerid"); line? i'm a newbie in this. thankyou :)

  11. You'd add it in whichever event you want to drive the action, whether it's the form's "OnLoad" event, or any field's "OnChange" event.

    1. I finally made it! It do work for CRM 2011. thanks a lot sir Dave! :) you saved my life..

  12. Good thinking there! I didn't expect this request from clients, but, it eventually came.
    Thank you for you work,


Unrelated comments to posts may be summarily disposed at the author's discretion.