Applies to Product - Dynamics 365 Finance
What’s happening?
The customer is seeking assistance in understanding the OData Batch API and its syntax to chain multiple OData entities together to create an atomic transaction, such as a header with multiple lines for that header.
Reason:
To chain multiple entities using the OData Batch API, changesets are utilized. Each changeset contains a list of requests that should be treated as a single atomic unit, meaning either all requests are executed successfully, or if any request fails, none of the requests are executed.
Resolution:
- Use changesets to bundle multiple requests into a single atomic unit.
- Ensure that the relationships between entities are explicitly defined during the development phase.
- For related entities, include special markers in the batch request to handle these relationships.
- Use the SaveChangesOptions.BatchWithSingleChangeset option in the SaveChanges() method to ensure that all requests are bundled into a single changeset.
- Example of sending a batch request with a list of requests in a single changeset: xpp public static void CreateProductColors(Resources context) { var productColorsCollection = new DataServiceCollection(context); var productColor1 = new ProductColor(); productColor1.Name = "New Color 1"; // set any other properties needed var productColor2 = new ProductColor(); productColor2.Name = "New Color 2"; // set any other properties needed context.SaveChanges(SaveChangesOptions.BatchWithSingleChangeset); }
- Refer to the Open Data Protocol (OData) documentation for further details on batch processing and entity relationships.
