1
votes

I am inserting records using the Dynamics web API batch insert operation. I am using the patch method and inserting on the alternate key. The response that I am receiving from the CRM is (response.Content) is giving the batch ID and the alternate keys that I have inserted. However, I'd like to fetch the GUIDs of the inserted records as well. Is there any way to read the GUIDs of the inserted records in the response itself. Using another query to get the GUIDs will be costly as I need to insert millions of records.

I tried using response.Content to read the response but as mentioned above, it did not include the GUIDs. I also tried running a different query to fetch the GUIDs of the specified alternate keys. This takes up a lot of time. Further, I tried generating GUIDs at the time of insertion (hence, eliminating the need of capturing them in the response) but the client doesn't want to use this method.

//This is how I am reading the response

HttpResponseMessage response = httpClient.SendAsync(request).Result;
var strCttResponse = await response.Content.ReadAsStringAsync();

//Please see the expected and actual result description

//Following is the sample response (for one record only). As you can see //it has only the alternate key and batch id.

--batchresponse_63bdc6fd-90f2-4a2b-b11d-ba4cc1d122f4
Content-Type: multipart/mixed; boundary=changesetresponse_ac69e917-8cf9-4ee8-8d4c-9d525ae6f4c3

--changesetresponse_ac69e917-8cf9-4ee8-8d4c-9d525ae6f4c3
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID: 1

HTTP/1.1 204 No Content
OData-Version: 4.0
Location: https://<URL>/api/data/v9.1/contacts(new_altkey_contact='46236')
OData-EntityId: https://<URL>/api/data/v9.1/contacts(new_altkey_contact='46236')

//--------------------------------------------------------------------------

The result that I am looking for should return the GUID of the inserted records as well. Something like:

 Batch Id

 https://<URL>/api/data/v9.1/contacts(new_altkey_contact='altkey')

 GUID of the record
1
I doubt that you can get the created record ids, as the batch request is like a queue where request is submitted & accepted, then executed asynchronously.Arun Vinoth - MVP

1 Answers

0
votes

Can you please verify the Response for a single create outside of an Batch. From what I have seen, you should also get the AlternateKey Back. You could also ask Microsoft if this is really intended. Is there a Special reason why you Need the GUID back? Yes, Alternate Key are slower because CRM Needs to ask internally for the GUID, but this schould not make any Impact beside Large Data Imports, for Exmaple for inital Data Migration