In CRM 2013, we have got two different functions one for saving the form and refreshing the form. Advantage of these two are that they are asynchronous in nature which can do the other activities based on the result of this refresh or save. So for example if we need to call function1 if the refresh/save was successful and function2 otherwise its pretty easy now.
We will look at refresh first,
Xrm.Page.data.refresh(save).then(
function () {
//Do something if the refresh is successful
},
function () {
//Do something if the refresh is unsuccessful
}
);
In the above example save is a boolean value which should be used to mention whether we need to save the form after it is refreshed. If true then the form will be saved and if not then the form will not be saved.
Next we will look at the save function.
Xrm.Page.data.save().then(
function () {
//Do something if the save operation is successful.
},
function () {
//Do something if the save operation is unsuccessful.
}
);
In both the above cases the success call back will not have any arguments. It will simply be called if the operation succeeds. At the same time error call back will be having an object with properties:
errorCode: The error code.
message: A localized error message.
One more thing to be noted for these functions are that these two are available only for updated entities.
Hope this helps!!!