Xrm.WebApi.online.executeMultiple (Client API reference)

Execute a collection of action, function, or CRUD operations.

Note

This method is supported only for the online mode (Xrm.WebApi.online).

If you want to execute multiple requests in a transaction, you must pass in a change set as a parameter to this method. Change sets represent a collection of operations that are executed in a transaction. You can also pass in individual requests and change sets together as parameters to this method.

Note

You cannot include read operations (retrieve, retrieve multiple, and Web API functions) as part of a change set; this is as per the OData v4 specifications.

Syntax

Execute multiple requests:

var requests = [req1, req2, req3];
Xrm.WebApi.online.executeMultiple(requests).then(successCallback, errorCallback);

Execute multiple requests in a transaction:

In this case, req1, req2, and req3 will be executed in transaction.

var changeSet = [req1, req2, req3];
var requests = [changeSet];
Xrm.WebApi.online.executeMultiple(requests).then(successCallback, errorCallback);

Execute a mix of individual requests and multiple requests in a transaction:

In this case, req1, req2, and req3 will be executed in transaction, but req4 and req5 will be executed individually.

var changeSet = [req1, req2, req3];
var requests = [req4, req5, changeset];
Xrm.WebApi.online.executeMultiple(requests).then(successCallback, errorCallback);

Parameters

Name Type Required Description
requests Array of objects Yes

An array of one of one of the following types:

  • objects where each object is an action, function, or CRUD request that you want to execute against the Web API endpoint. Each object exposes a getMetadata method that lets you define the metadata for the action, function or CRUD request you want to execute. This is the same object that you pass in the execute method. For information about the object, see execute.
  • Change set (an array of objects), where each object in the change set is as defined above. In this case, all the request objects specified in the change set will get executed in a transaction.

See request examples earlier in the **Syntax** section for more information.

successCallback Function No

A function to call when operation is executed successfully. An array of response objects are passed to the function where each response object has the following attributes:

  • body: (Optional). Object. Response body.
  • headers: Object. Response headers.
  • ok: Boolean. Indicates whether the request was successful.
  • status: Number. Numeric value in the response status code. For example: 200
  • statusText: String. Description of the response status code. For example: OK
  • type: String. Response type. Values are: the empty string (default), "arraybuffer", "blob", "document", "json", and "text".
  • url: String. Request URL of the action, function, or CRUD request that was sent to the Web API endpoint.
errorCallback Function No A function to call when the operation fails.

Return Value

On success, returns a promise containing an array of objects with the attributes specified earlier in the description of successCallback function.

Xrm.WebApi