Advertisements
Home > CRM 2013 > Identify “Auto Save” in JScript onload & onsave events – CRM 2013

Identify “Auto Save” in JScript onload & onsave events – CRM 2013

CRM 2013 has got a new ‘Auto Save” feature which periodically saves the form after new data entered.

Problem with frequent auto save

  • The problem with this design is whenever auto-save fires, it causes  unwanted execution of the registered onload & onsave events.

To identify ‘Auto Save’ event in ‘onload & onsave’ below is useful approach

On Save 

  • Check  the ‘Save Mode’ of ‘Event Args’, If Save Mode is ‘70’ then save event is caused by ‘Auto Save’
  • Make sure to check ‘Pass execution context as first parameter’ while registering ‘onsave’ event
Passing execution context

Passing execution context

function onsave(eventArgs) {

var saveMode = eventArgs.getEventArgs().getSaveMode();

// 70 – AutoSave

if (saveMode == 70) {

alert(“Save caused by AutoSave”);

// By setting Form dirty, we will make sure the traditional save event executes when you click on ‘Save’ button

Xrm.Page.data.setFormDirty(true);

}

else {

alert(“Traditional Save event”);

}

}

Note

  • Since the ‘AutoSave’ periodically saves the form data, you might not get traditional ‘onsave’ event fired.
  • If you want your logic to be executed in traditional ‘onsave’ event, set form dirty to ‘true’ in ‘AutoSave’ save mode.

On Load 

‘onload’ event caused by ‘AutoSave’ does not clears the global variables. So use below steps to check ‘AutoSave’ event on ‘onload’

  • Declare and set a global variable
  • Check the variable on onload event

var formLoaded = false;

function onload() {

if (!formLoaded) {

alert(“Traditional form load happend !!!”);

}

formLoaded = true;

}

  • Above function the ‘If’ block executes only first time when you open the form

🙂

Advertisements
Categories: CRM 2013 Tags: , ,

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

%d bloggers like this: