2010/02/03

Adding tooltips to CRM and help developers getting the attribute name using the tooltip

Found the wonderful post from Andriy on his blog Setting the description field of the attribute as a tooltip in CRM.
We changed the code a bit to make it easier for developers to access the attribute name based on the field's tooltip.

Step 1: Copy the code in onload event of the form
at the bottom of the post.
Step 2:Publish the changes
Step 3:Load the relevant page
Step 4:Click with your mouse on the display name of attribute

Step 5:Keeping your (Crtl) keyboard key in, click with your mouse on the tooltip.
Step 6: Open Notepad
Step 7: press (Crtl +v) and the database name will be pasted in notepad.


You will not have to have the customization window open any more to see the attributes and database names.

SetTooltips = function() {
try {
var request = "" +
"<?xml version="1.0" encoding="utf-8"?>" +
"<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">" +
GenerateAuthenticationHeader() +
" <soap:Body>" +
" <Execute xmlns="http://schemas.microsoft.com/crm/2007/WebServices">" +
" <Request xsi:type="RetrieveEntityRequest">" +
" <RetrieveAsIfPublished>true</RetrieveAsIfPublished>" +
" <EntityItems>IncludeAttributes</EntityItems>" +
" <LogicalName>" + crmForm.ObjectTypeName + "</LogicalName>" +
" </Request>" +
" </Execute>" +
" </soap:Body>" +
"</soap:Envelope>";

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

xmlHttpRequest.Open("POST", "/mscrmservices/2007/MetadataService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Execute");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", request.length);
xmlHttpRequest.send(request);

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");
try {
if (desc != null) {
crmForm.all[fieldName + '_c'].title = desc.nodeTypedValue;
crmForm.all[fieldName + '_d'].title = desc.nodeTypedValue;
}
crmForm.all[fieldName + '_c'].children[0].onclick = function() { copyFieldNameToClipboard(fieldName) };
}
catch (e) { }
}
} catch (e) {
}

function copyFieldNameToClipboard(fieldName) {
if (event.srcElement.tagName.toLowerCase() == 'label' && event.ctrlKey)
clipboardData.setData('text', event.srcElement.attributes['for'].value);
}
}

setTimeout('SetTooltips();', 1500);