Thursday, August 9, 2012

Show/copy ID (Guid) of Entity Record in CRM Form

While working on CRM projects, it's often necessary to get the GUID for an entity record within the CRM UI. One way to do this is to use the Copy Link feature from the form, paste the link to notepad, and then manually extract the id. A faster approach is to create a browser Favorite that runs JavaScript that reveals the ID, making it easy for you to copy.

Setting Up the Browser Favorite

  • Open up an entity form and then press Ctrl+N to open the form in a new window that has the address bar showing.
  • Add that current page as a Favorite
  • Edit the properties of the Favorite. On the General tab, type "Show GUID" as the shortcut's name.  On the Web Document tab, provide the JavaScript shown below.

javascript:(function() {var d=document.URL;var s = d.search(/id(%)3d(%)257b[A-F0-9]{8}(?:-[A-F0-9]{4}){3}-[A-Z0-9]{12}/);window.prompt('Record ID:',d.substring(s+10, s+46))})();

  • Click OK to save the Favorite.


Using the Favorite to Show an Entity Record's ID

  • Open an entity form.
  • Press Ctrl+N to open a new window that shows the Favorites bar.
  • Click the Favorite to show the record's ID.

2 comments:

  1. Hey, this is cool, thanks. It's very helpful for stripping a Guid from any URL in a browser. Can add 'a-z' (lowercase) to all the character classes in the regex so it will work with lowercase, too.

    ReplyDelete
  2. Instead of showing message box, it's possible to copy the GUID directly to clipboard using this code:

    window.clipboardData.setData("Text", guidValue);

    ReplyDelete