There are a few options to overcome this issue. This blog is discussing two of those options.For this blog, I am using the logic app created in the last blog (http://mscrmshop.blogspot.com.au/2018/03/d365-web-api-batch-request-transaction.html). This blog creates a contact record with two address records.
Option 1(Create the Contact record GUID Manually)
The one option is to generate a GUID before invoking the batch request and use this GUID to create the contact record and related address records.The following screenshots depict the changes in the logic app.
- The first screenshot displays all the steps for the logic app.
- The second screenshot displays the step to generate a new GUID for the contact. This step is using Initialize Variable action.
- The third screenshot shows the part of the batch request. The screenshot also highlights where the GUID is used to create a new contact and related address records.
Note:
The creation of a manual GUID is not recommended for performance reasons. If the number of users and transaction volume can handle the performance hit, only then use this option. Otherwise, consider the second option.Option 2 (Deep Insert)
The second option is not to use the batch request. The transaction integrity can be achieved using the deep insert.This option allows us to create a new record and its related records in one operation. If the creation of any of the records fails, the system fails the whole operation.
The following screenshot displays the deep insert web API call.
Update Considerations
The above two options are useful for creating new records. If you want to update multiple child records based on a parent record, then consider making two API calls:- The first call to retrieve the GUID of the parent record based on available attribute/attributes (e.g., first name, last name, email, and address)
- The second call (batch request) to update the child records based on the GUID retrieved in the first call.
Download Links
You can download the logic apps created for this blog from the following links:
That is it. If you have a better solution, please share it.
That is it. If you have a better solution, please share it.