In dynamics-web-api, when using batch, how to use content-id as a key of an update request?

241 Views Asked by At

Npm package: https://www.npmjs.com/package/dynamics-web-api

Version: 1.6.12

this.dynamicsWebApi.startBatch();
this.dynamicsWebApi.createRequest({
  collection: 'accounts',
  entity: createdAccountData,
  contentId: '1',
});
this.dynamicsWebApi.createRequest({
  collection: 'contacts',
  entity: {
     ...contactData,
     '[email protected]': '$1',
  },
  contentId: '2',
});
this.dynamicsWebApi.updateRequest({
  collection: 'accounts',
  key: '$1',
  entity: {
    '[email protected]': '$2',
  },
});
await this.dynamicsWebApi.executeBatch();

From the above code, I intend to create an account, a contact that links to the account, and finally, update the account to link to the contact.

CreateRequest 1 and 2 could execute successfully, but the updateRequest failed with the error message "DynamicsWebApi.executeBatch requires the request.key parameter to be of type String representing GUID or Alternate Key"

My question is that there is any way to use the contentId 1 as the key of the updateRequest?

1

There are 1 best solutions below

0
On

You can use the deep insert to create account and contact record and link them.