Skip to content

Commit 8981c0e

Browse files
upd: readme
1 parent 9f29d9d commit 8981c0e

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed

README.md

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ please go to `node_modules\dynamics-web-api` of your application and remove `.gi
6666
* [Delete Global Option Set](#delete-global-option-set)
6767
* [Retrieve Global Option Set](#retrieve-global-option-set)
6868
* [Retrieve Multiple Global Option Sets](#retrieve-multiple-global-option-sets)
69+
* [Execute Batch Operations](#execute-batch-operations)
6970
* [Formatted Values and Lookup Properties](#formatted-values-and-lookup-properties)
7071
* [Using Alternate Keys](#using-alternate-keys)
7172
* [Making requests using Entity Logical Names](#making-requests-using-entity-logical-names)
@@ -1599,6 +1600,66 @@ dynamicsWebApi.retrieveGlobalOptionSets('Microsoft.Dynamics.CRM.OptionSetMetadat
15991600
});
16001601
```
16011602

1603+
## Execute Batch Operations
1604+
1605+
`version 1.5.0+`
1606+
1607+
Batch requests bundle multiple operations into a single one and have the following advantages:
1608+
1609+
* Reduces a number of requests sent to the Web API server. `Each user is allowed up to 60,000 API requests, per organization instance, within five minute sliding interval.` [More Info](https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/api-limits)
1610+
* Provides a way to run multiple operations in a single transaction. If any operation that changes data (within a single changeset) fails all completed ones will be rolled back.
1611+
* All operations within a batch request run consequently (FIFO).
1612+
1613+
Batch requests are not simple to compose and DynamicsWebApi provides an easy way to execute such operations:
1614+
1615+
```js
1616+
1617+
//when you want to start a batch operation call the following function:
1618+
//it is important to call it, otherwise all operations below will be executed right away.
1619+
dynamicsWebApi.startBatch();
1620+
1621+
//call necessary operations just like you would normally do.
1622+
//these calls will be converted into a single batch request
1623+
dynamicsWebApi.retrieveMultiple('accounts');
1624+
dynamicsWebApi.update('00000000-0000-0000-0000-000000000002', 'contacts', { firstname: "Test", lastname: "Batch!" });
1625+
dynamicsWebApi.retrieveMultiple('contacts');
1626+
1627+
//execute a batch request:
1628+
dynamicsWebApi.executeBatch()
1629+
.then(function (responses) {
1630+
//'responses' is an array of responses of each individual request
1631+
//they have the same sequence as the calls between startBatch() and executeBatch()
1632+
//in this case responses.length is 3
1633+
1634+
//dynamicsWebApi.retrieveMultiple response:
1635+
var accounts = responses[0];
1636+
//dynamicsWebApi.update response
1637+
var isUpdated = responses[1]; //should be 'true'
1638+
//dynamicsWebApi.retrieveMultiple response:
1639+
var contacts = responses[2]; //will contain an updated contact
1640+
1641+
}).catch(function (error) {
1642+
//catch error here
1643+
});
1644+
1645+
```
1646+
1647+
**Important!** Developers who use DynamicsWebApi with callbacks do not need to pass `successCallback` and `errorCallback` in an individual operation when `startBatch()` is called,
1648+
just pass `null` if you need to add additional parameters in the request.
1649+
1650+
Currently, there are some limitations in DynamicsWebApi Batch Operations:
1651+
1652+
* `Content-ID` header cannot be used to reference the Uri of any entity created in a single operation. **This is an upcoming feature**.
1653+
* Operations that use pagination to recursively retrieve all records cannot be used in a batch operation. These operations include: `retrieveAll`, `retrieveAllRequest`, `countAll`, `fetchAll`, `executeFetchXmlAll`.
1654+
You will get an error saying that the operation is incompatible in a 'batch mode'.
1655+
1656+
There are also some Web API limitations for batch operations:
1657+
1658+
* Batch requests can contain up to 100 individual requests and cannot contain other batch requests.
1659+
* The odata.continue-on-error preference is not supported by the web API. Any error that occurs in the batch will stop the processing of the remainder of the batch.
1660+
1661+
You can find an official documentation that covers Web API batch requests here: [Execute batch operations using the Web API](https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/webapi/execute-batch-operations-using-web-api)
1662+
16021663
## Formatted Values and Lookup Properties
16031664

16041665
Starting from version 1.3.0 it became easier to access formatted values for properties and lookup data in response objects.
@@ -1768,7 +1829,8 @@ the config option "formatted" will enable developers to retrieve all information
17681829
- [X] Ability to use entity names instead of collection names. `Implemented in v.1.4.0`
17691830
- [X] Entity and Attribute Metadata helpers. `Implemented in v.1.4.3`
17701831
- [X] Entity Relationships and Global Option Sets helpers. `Implemented in v.1.4.6`
1771-
- [ ] Batch requests.
1832+
- [X] Batch requests.
1833+
- [ ] Implement `Content-ID` header to reference a created entity in batch operation.
17721834
- [ ] Intellisense for request objects.
17731835

17741836
Many more features to come!

0 commit comments

Comments
 (0)