Wednesday, August 26, 2009

CRM: Working Outside the CRM SDK

A client asked: Is it possible to hide controls outside of the CRM SDK?

Yes, you can, however, this solution is technically unsupported by Microsoft as it goes outside the CRM SDK, however the customization is small and easy to reverse to get into a state where Microsoft is supported.

Below are some code samples on how to hide attributes, elements and sections. These are quick JavaScript solutions for hiding both controls on a CRM page and links in the left-hand navigation page on an Entity Form.

The code below provides three functions that can be used to show/hide specific items on a CRM form:

var HIDE = 'none';
var SHOW = 'block';

// Function to show/hide CRM controls on a CRM form
// such as text boxes, lookups, pick-lists etc.
function SetCrmControlVisible(elementName, visibility)
SetElementVisible(elementName + '_c', visibility);
SetElementVisible(elementName + '_d', visibility);

// Fuction to show/hide specific elements on a CRM form
// such as the left-hand link items (More Addresses, Workflows
// and even custom ISV links
function SetElementVisible(elementId, visibility)
var elem = document.getElementById(elementId);
if (elem != null)
{ = visibility;

// Function to show/hide Navigation "Sections" in the left-hand
// links (Such as Sales, Marketing and Service)
function SetParentElementVisible(elementId, visibility)
var elem = document.getElementById(elementId);
if (elem != null && elem.parentElement != null)
{ = visibility;

Add the above code to the Entity OnLoad andyou are ready to show/hide elements on the CRM form.

Using the IE Developer toolbar, you can retrieve the id of the element to be hidden Open an entity record (in this case a Contact), press CTRL+N to open it in a new window, and then select IE Developer Toolbar.

Using the controls, select the item you want to hide and get the element id. In this case we have selected the “Opportunities” link and the id is “navOpps”

Using this, I can call the SetElementVisible function like this to hide the Opportunities link:

SetElementVisible('navOpps', HIDE);

To hide the entire “Sales” section from the left-hand navigation pane, I can once again find the id, but this time is of the parent item which would result in the following call to hide it:

SetParentElementVisible('_NA_SFA', HIDE);

Lastly, to hide an element on the form such as the “Job Title” field, you once again should use the IE Developer Toolbar to retrieve the element id and then call the SetCrmControlVisible function:

SetCrmControlVisible('jobtitle', HIDE);

By selecting either the textbox or the label, for the Job Title, the returned id will be “jobtitle_c” or “jobtitle_d” – remove everything including and after the “_” and pass that to the SerCrmControlVisible function and you are done!

No comments: