1

Closed

Sync action call

description

Hi ,

I'm facing an issue where I need to validate some data on a form using an action and only submit the form if the data is valid.

The fact that the action call has to be asynchronous I can't not prevent the save event only after the action call callback finished.

I therefore modified your code to allow the underlying XMLHttpRequest to be made synchronously.

I gave an additional 'async' parameter to the callAction method and therefore the _callActionBase as well

Here is what I've done:
  • callAction method:
Process.callAction = function (actionName, inputParams, successCallback, errorCallback, async, url) {
...
Process._callActionBase(requestXml, successCallback, errorCallback, url, async);
}
  • _callActionBase method:
Process._callActionBase = function (requestXml, successCallback, errorCallback, url, async) {
    if (url == null) {
        url = Xrm.Page.context.getClientUrl();
    }
    if(async == null){
        async = true;
    }

    var req = new XMLHttpRequest();
    req.open("POST", url + "/XRMServices/2011/Organization.svc/web", async);
    req.setRequestHeader("Accept", "application/xml, text/xml, */*");
    req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
...
Any chances that you would implement something similar in your project so that I can follow your updates without having to maintain my own separate version ?

Thank you
Closed Jan 31 at 1:41 AM by Liger_cp <SND\Liger_cp>
By design

comments

majblackburn wrote Jan 20 at 1:50 AM

Couldn't you cancel the default action in the onSave handler, call the action, and submit the save in the asynchronous success handler?

Liger wrote Jan 31 at 1:41 AM

I decided to make it async otherwise it locks the UI, and calling actions is quite slow, so it's not a nice user experience to lock up the UI for a second or two while it does its thing. In your case as someone else wrote you can cancel the save event before opening the alert, then on confirmation fire the save again.

wrote Jan 31 at 1:41 AM