JavaScript serviceIsBusy error OnSave of CRM form?

494 views Asked by At

CRM 365 OnPremise.

I have an Accounts.js that contains the following code simplified for the example:

Xrm.Page.data.save().then(
    function() {
        Xrm.Utility.alertDialog("Record saved");
     },
    function(error) {
        Xrm.Utility.alertDialog(error.message);
    });

The idea is that the form saves, then when the async save is complete it triggers the alert dialog to say 'record saved'.

The problem is that the error function is being triggered, but the error is simply 'serviceIsBusy'.

Can anyone explain how to get around this or what the problem is?

2

There are 2 answers

0
DaveC On BEST ANSWER

Sadly the official way does not work for OnPremise CRM 365. I have absolutely no idea why and even less time to troubleshoot.

The solution i found somewhere on stack overflow was this 'old' way:

   //trigger form save and wait 1 sec
    Xrm.Page.data.entity.save();
    setTimeout(function () {
        saveAccountOK(context);
    }, 3000);
4
Arun Vinoth-Precog Tech - MVP On

Actually Xrm.Page.data.save() is to invoke the same save button action from the entity form, but if you call this method from the form save event itself then it will endup in loop.

Since you want to make use of .then() handler for custom need, you can prevent the default save operation and invoke the manual save as you do.

You can understand form this community thread.

function onSave(context){
    context.getEventArgs().preventDefault();

    Xrm.Page.data.save().then(
      function() {
        Xrm.Utility.alertDialog("Record saved");
     },
      function(error) {
        Xrm.Utility.alertDialog(error.message);
    });
}