Showing Entity Logical Names on Forms in Dynamics CRM 2011 & 2013

While there are a few scripts out there that sets the labels for fields on a CRM form to be the logical names, they aren't the quickest to copy/paste from. These scripts also remove the existing field labels which can sometimes make it hard to identify fields especially if the name of fields have changed. It might not be obvious to someone new to a project that two years ago the "Technichal Specialist" role was renamed to "Solution Architect" while the logical name of the field stayed the same.

To make things easier, I wrote a script that shows all controls, sections, and tabs then inserts a textbox next to the existing field labels and selects the text when the textbox is focused to make it easy to copy. It also widens the labels displayed on the form to make room for showing both a textbox and the existing label. While this can crowd out the input, the primary purpose is for quickly pulling out logical names anyways.

 

The script works in both CRM 2011 and 2013. To run it, execute the following in a the browser's console:

(function(){var frm=(window.Xrm&&window.Xrm.Page&&window.Xrm.Page.ui&&window)||(frames[1]&&frames[1].Xrm&&frames[1].Xrm.Page.ui&&frames[1])||frames[0];var Xrm=frm.Xrm;if(!Xrm||!Xrm.Page||!Xrm.Page.ui){alert('Unable to find CRM form');return;}Xrm.Page.ui.tabs.forEach(function(tab){tab.setVisible(true);tab.sections.forEach(function(section){section.setVisible(true);});});var $=frm.jQuery||(frm.CEI&&frm.CEI.$);if(!$){var head=frm.document.getElementsByTagName('head').item(0);var s=frm.document.createElement('script');s.setAttribute('type','text/javascript');s.setAttribute('src','https://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.js');s.async=false;head.appendChild(s);waitForJQ();}else{setLabels();}function waitForJQ(){if(frm.jQuery){$=frm.jQuery.noConflict(true);setLabels();}else{setTimeout(waitForJQ,1000);}}function setLabels(){Xrm.Page.data.entity.attributes.forEach(function(a){a.controls.forEach(function(c){var lblText=c.getLabel();c.setVisible(true);var attr=a.getName();var lbl=$('#'+c.getName()+'_c').html('');lbl.css('text-align','left');if(lbl.is('td')){lbl.closest('table').children('colgroup').children('col:even').attr('width','400');}$('<input/>').width(200).val(attr).appendTo(lbl).focus(function(){$(this).select()});$('<span></span>').text(lblText).appendTo(lbl);});});}})();

Or, create a bookmarklet for the following:

javascript:(function(){var frm=(window.Xrm&&window.Xrm.Page&&window.Xrm.Page.ui&&window)||(frames[1]&&frames[1].Xrm&&frames[1].Xrm.Page.ui&&frames[1])||frames[0];var Xrm=frm.Xrm;if(!Xrm||!Xrm.Page||!Xrm.Page.ui){alert('Unable to find CRM form');return;}Xrm.Page.ui.tabs.forEach(function(tab){tab.setVisible(true);tab.sections.forEach(function(section){section.setVisible(true);});});var $=frm.jQuery||(frm.CEI&&frm.CEI.$);if(!$){var head=frm.document.getElementsByTagName('head').item(0);var s=frm.document.createElement('script');s.setAttribute('type','text/javascript');s.setAttribute('src','https://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.js');s.async=false;head.appendChild(s);waitForJQ();}else{setLabels();}function waitForJQ(){if(frm.jQuery){$=frm.jQuery.noConflict(true);setLabels();}else{setTimeout(waitForJQ,1000);}}function setLabels(){Xrm.Page.data.entity.attributes.forEach(function(a){a.controls.forEach(function(c){var lblText=c.getLabel();c.setVisible(true);var attr=a.getName();var lbl=$('#'+c.getName()+'_c').html('');lbl.css('text-align','left');if(lbl.is('td')){lbl.closest('table').children('colgroup').children('col:even').attr('width','400');}$('<input/>').width(200).val(attr).appendTo(lbl).focus(function(){$(this).select()});$('<span></span>').text(lblText).appendTo(lbl);});});}})();

This will cause the form to display attribute logical names:

Capture

 

 

Show Buttons
Hide Buttons