Thursday, January 07, 2010

Setting attribute description as a tooltip for a field in entities forms in Microsoft Dynamics CRM 4.0

There is simple way to set tooltip text for field on CRM form. You can do it with following script placed on OnLoad event handler of some CRM form:

crmForm.all.<field name>_c.title = 'Tooltip text';
crmForm.all.<field name>_d.title = 'Tooltip text';

It will be hard work to create detailed tooltips for all fields placed on form
using this script. I've decided to develop script which will set text of field's tooltip based on description of field in attribute customization form.

To make this possible only add following script to OnLoad event handler of entity form:

SetTooltips = function()
var request = "" +
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:soap=\"\" xmlns:xsi=\"\" xmlns:xsd=\"\">" +
GenerateAuthenticationHeader() +
" <soap:Body>" +
" <Execute xmlns=\"\">" +
" <Request xsi:type=\"RetrieveEntityRequest\">" +
" <RetrieveAsIfPublished>true</RetrieveAsIfPublished>" +
" <EntityItems>IncludeAttributes</EntityItems>" +
" <LogicalName>" + crmForm.ObjectTypeName + "</LogicalName>" +
" </Request>" +
" </Execute>" +
" </soap:Body>" +

var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

xmlHttpRequest.Open("POST", "/mscrmservices/2007/MetadataService.asmx", false);
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", request.length);

var result = xmlHttpRequest.responseXML;

for(var i = 0; i < crmForm.all.length; i++)
if(crmForm.all[i].title != null && crmForm.all[i].title != 'undefined')
var fieldName = crmForm.all[i].id;

var desc = result.selectSingleNode("//EntityMetadata/Attributes/Attribute[LogicalName='" + fieldName + "']/Description/UserLocLabel/Label");
if(desc != null)
crmForm.all[fieldName + '_c'].title = desc.nodeTypedValue;
crmForm.all[fieldName + '_d'].title = desc.nodeTypedValue;
catch(e) {}


And the result you can see here:


  1. This comment has been removed by the author.

  2. Somehow it didn't worked for me. I pasted the code in the Contact entity's Form onLoad event, enabled it and published the changes....

  3. I could not get this to work either, perhaps we need a txt file with the code in it? When I used it it actually caused a embeded IFRAME to fail as well.

  4. I haven't tried it to use with Iframes but I think it must work. Actually no text files is needed.

  5. Hello Andriy,

    Recently I posted an alternative way of displaying tooltips. It requires a custom entity in which you can store the tooltips per entity/attribute. See this post:

    I'm planning to expand this function to support multiple languages.


  6. Hello.

    Awesome! To make easier developing the solution which will support multiple languages you can check stunnware blog for a sample. Michael has solution which can be used.

  7. This works great for me if I'm System Administrator og System Customizer. Not if I'm just Sales Person. Any idea on what to set in User Rights?

  8. Hello. Try to give to Sales Person Role Permission to read Attributes at Customization tab.

  9. Hi Andriy,
    Your script is exactly what I need for CRM 2011.
    Do you have a version of this that works for CRM 2011?