[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 currentSpan.style.textDecoration = "none"; currentSpan.style.color = "#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:
DisableLookupLinks("customerid");
The code also conveniently works for multi-record Lookup fields, such as party-lists on activity records.
Your code was reposted without any reference to you, dear Dave. How I hate such reposting...
ReplyDeletehttp://bproud2banindian.blogspot.com/2010/10/disable-links-in-lookup-field-ms-crm-40.html
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.
ReplyDeleteI'm just glad to have friends like you who keep a watchful eye for those "bad actors."
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
ReplyDeleteDear Anonymous.
ReplyDeleteThis is for sure is copypasting.
Andriy,
ReplyDeleteIt is obvious theat he copy and paste.
Thanks for the function Dave....
ReplyDeleteI added two more lines in my function as below to make the text not to look like a hyperlink. :)
var currentSpan = lookupSpanNodes[spanIndex];
currentSpan.style.textDecoration = "none";
currentSpan.style.color = "#000000";
currentSpan.onclick = function() {};
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!
ReplyDeleteHi Dave,
ReplyDeleteI'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!
Ryan
You're welcome, Ryan. It is a pleasure, and I thank you for such a kind note!
ReplyDeletehi.. 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 :)
ReplyDeleteYou'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.
ReplyDeleteI finally made it! It do work for CRM 2011. thanks a lot sir Dave! :) you saved my life..
DeleteGood thinking there! I didn't expect this request from clients, but, it eventually came.
ReplyDeleteThank you for you work,
Sander