JavaScript Bookmark Series – Part 1

Posted by on August 13, 2012  |  commentsComments (2)

Today we’ll be kicking off a series of posts about JavaScript bookmarks that can be useful to CRM developers and customizers.  These bookmarks are easy to setup and could help save some time.  To create these bookmarks, just browse to any CRM page and add it to your favorites (This will get you the lovely CRM logo).  Then, you can edit the bookmark and set the URL to the JavaScript mentioned in the post.

image

The first bookmark in the series will alert any fields that are dirty on a CRM form.  As a developer, you’ll know that sometimes forms become perpetually dirty due to some custom JavaScript that is manipulating a field value automatically.  This makes the pesky “Are you sure you want to leave this page?” alert show up when the user closes the form even if they didn’t change a value.

To easily debug this issue, make a bookmark setting the URL to the following:

javascript:var message="The following fields are dirty: \n";window.frames[0].Xrm.Page.data.entity.attributes.forEach(function(attribute,index){if(attribute.getIsDirty()==true){message+="\u2219 "+attribute.getName()+"\n";}});alert(message);

Now browse to the ‘dirty’ CRM form and click your new bookmark.  This should alert the names of all the fields that are dirty.

That concludes our first bookmark of the series!  Let us know in the comments if you have any suggestions for a useful bookmark.

Comments

  1. Very useful! After reading this I created my own bookmark to retrieve the entity id from a page and put it on the clipboard. This saves med from having to locate it manually in the page URL, selecting it and copying it.

    javascript: var id = frames[0].Xrm.Page.data.entity.getId().replace(/[{}]/g, ''); window.clipboardData.setData('text', id);

    Thanks for a good tip! :)

    Posted by: Harald Svendberg  |  Aug 16, 2012 3:08:16 AM

  2. Thanks Harald! That is actually part of the next piece in the series :)

    Posted by: Blake Scarlavai  |  Aug 17, 2012 9:30:36 PM

Post a Comment

  • *Required

Contact Us for a Quote, or Personalized Demonstrationof Microsoft Dynamics CRM for Your Business.

Contact Us