Temporarily Disable Auto Save in CRM 2013 with Bookmarklet

Posted: July 29, 2014 in Dynamics CRM 2013, JavaScript

In Dynamics CRM 2013, when auto save is enabled, any changes to a record will be saved automatically when you close the record. In some cases we need to change data on a record to test functionality, and so we don’t always want those changes to be saved.

I’ve created a browser bookmarklet which will disable auto save for the record you have open, so that if you ever need to enter some test data into a record, you can simply click the bookmark which will prevent the system from automatically saving the form every 30 seconds, and also when you close the record or navigate away.

What the script does is it attaches an onsave event which checks the save mode, and cancels the save event for anything other than a physical ‘Save’, which can only be triggered by the little save icon in the bottom right corner (or my save bookmarklet). Any other type of save, including auto save and save and close, will be prevented. When you close the record or navigate away with unsaved changes, you will be prompted that there are unsaved changes just like it would if auto save was disabled for the organisation.

As you can see above, I’ve clicked the ‘Disable Auto Save’ bookmarklet, then made some changes to the Account Name, and when we navigate away we’re prompted that changes have not been saved. We can then simply click ‘Ok’ to close the form without saving the changes. The next time we open the record, or when we open any other record, auto save will be enabled again until. This allows us to turn off auto save only when required.

The script to use for this bookmark is as follows:

javascript: var frame = $("iframe").filter(function () { return ($(this).css('visibility') == 'visible') }); frame[0].contentWindow.Xrm.Page.data.entity.addOnSave(function(context){ if (context.getEventArgs().getSaveMode() != 1) { context.getEventArgs().preventDefault(); } });
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s