I know these operations seem like very basic functionalities that have been around for a while. I wanted to point a specific new feature that comes with CRM 2013: the ability to run a callback method after a refresh or after a save triggered from a JavaScript method.
In the past, using the old Xrm.Page.data.entity.save method caused a refresh of the page which dismissed any code after the save in your script. Take this scenario for example…
- You have button in your ribbon on an Account form
- The button calls an external web service to update some of the account field values based on the account’s Primary Contact value which is on editable on the form
- The web service only takes the account id as a parameter, it loads the records, reads it and takes action
With the old save method, you had to require that the user saves the account so that the value of Primary Contact is saved to the database, then click your button that will call the web service with account ID. Such a requirement certainly causes pain in user experience especially if there are a lot of situations where they need to hit save, wait for refresh and click another button.
With the new Save and Refresh, we now have the possibility to add callback methods:
Xrm.Page.data.refresh(save).then(successCallback, errorCallback); // Parameters // save => A Boolean value to indicate if data should be saved after it is refreshed. // successCallback => A function to call when the operation succeed // errorCallbak => A function to call when the operation fails. It gets called with 2 parameters (an error code and a localized error message) Xrm.Page.data.save().then(successCallback, errorCallback); // Parameters // successCallback => A function to call when the operation succeed // errorCallbak => A function to call when the operation fails. It gets called with 2 parameters (an error code and a localized error message)
Having had this problem in the past makes this one a good candidate for most exciting new client API feature for me 🙂
Cheers
[…] See my blog post on this here […]
[…] See my blog post on this here […]
[…] you can read full artical from following linkhttps://thedynamicscrmblog.wordpress.com/2013/12/04/crm-2013-client-api-save-refresh/ […]
[…] A note here on successcallback and errorcallback methods can be found here:https://thedynamicscrmblog.wordpress.com/2013/12/04/crm-2013-client-api-save-refresh/ […]
I’m able to get this to work in my CRM 2013 On-Premise Environment, but not my Online Environment. IE 9,10,11 and Firefox (not Chrome), crashes after my code gets through the Save.
More extensive details at http://stackoverflow.com/questions/23273585/crm-2013-javascript-save-and-refresh-crashes