Skip to content

Commit 601e031

Browse files
updating readme
1 parent 9d83cf8 commit 601e031

File tree

2 files changed

+106
-18
lines changed

2 files changed

+106
-18
lines changed

.github/CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
<a name="v2.2.1"></a>
2+
# [v2.2.1](https://github.com/AleksandrRogov/DynamicsWebApi/releases/tag/v2.2.1) - 20 Feb 2025
3+
4+
**Fixes**
5+
- Wrong line endings in the batch request resulted in `InnerException : System.ArgumentException: Stream was not readable` when `inChangeSet` was set to `false`. [#183](https://github.com/AleksandrRogov/DynamicsWebApi/issues/183)
6+
7+
[Changes][v2.2.1]
8+
9+
110
<a name="v2.2.0"></a>
211
# [v2.2.0](https://github.com/AleksandrRogov/DynamicsWebApi/releases/tag/v2.2.0) - 09 Feb 2025
312

@@ -8,7 +17,7 @@
817
- Slightly optimized `dateReviver` function.
918

1019
**Fixes**
11-
- Modified `expand` property in the type definitions to accept a `string`. It could always accept a `string` instead of an array of expand objects.
20+
- Modified `expand` property in the type definitions to accept a `string`. It could always accept a `string` together with an array of expand objects.
1221

1322
[Changes][v2.2.0]
1423

@@ -1004,6 +1013,7 @@ Added:
10041013
[Changes][v1.2.0]
10051014

10061015

1016+
[v2.2.1]: https://github.com/AleksandrRogov/DynamicsWebApi/compare/v2.2.0...v2.2.1
10071017
[v2.2.0]: https://github.com/AleksandrRogov/DynamicsWebApi/compare/v2.1.7...v2.2.0
10081018
[v2.1.7]: https://github.com/AleksandrRogov/DynamicsWebApi/compare/v.2.1.6...v2.1.7
10091019
[v.2.1.6]: https://github.com/AleksandrRogov/DynamicsWebApi/compare/v2.1.5...v.2.1.6

.github/README.md

Lines changed: 95 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,44 @@ const result = await dynamicsWebApi.create<Lead>(request);
446446
const leadId = result.leadid;
447447
```
448448

449+
#### Create a table row with a related record in a single operation
450+
451+
Creating an account with a related contact:
452+
453+
```ts
454+
const id = await dynamicsWebApi.create({
455+
collection: "accounts",
456+
data: {
457+
name: "Test Account",
458+
primarycontactid: {
459+
firstname: "Test Related Contact"
460+
}
461+
}
462+
});
463+
464+
//if created record should be returned instead of an id, use returnRepresentation
465+
466+
const createdAccount = await dynamicsWebApi.create({
467+
collection: "accounts",
468+
data: {
469+
name: "Test Account",
470+
primarycontactid: {
471+
firstname: "Test Related Contact"
472+
}
473+
},
474+
//make sure to return only columns that are necessary to increase the performance
475+
returnRepresentation: true,
476+
select: ["name"],
477+
expand: [{
478+
property: "primarycontactid",
479+
select: ["firstname"]
480+
}]
481+
});
482+
483+
const accountName = createdAccount.name;
484+
const contactFirstName = createdAccount.primarycontactid.firstname;
485+
```
486+
449487
### Update a table row
450488

451489
```ts
@@ -1145,8 +1183,7 @@ const contactId = responses[0];
11451183
const salesorderId = responses[1];
11461184
```
11471185
1148-
**Important!** Web API seems to have a limitation (or a bug) where it does not return the response with `returnRepresentation` set to `true`. It happens only if you are trying to return a representation of an entity that is being
1149-
linked to another one in a single request. [More Info and examples is in this issue](https://github.com/AleksandrRogov/DynamicsWebApi/issues/112).
1186+
**Important!** Web API seems to have a limitation (or a bug) where it does not return the response with `returnRepresentation` set to `true` when `expand` is provided with `update` or `upsert` operations. [More Details](#returnrepresentation-with-expand-throws-an-error)
11501187
11511188
### Controlling Change Sets
11521189
@@ -1156,7 +1193,7 @@ In some cases this can be an undesirable behaviour and with v2 there are several
11561193
11571194
**Important!** `contentId` can **only** be used inside the Change Sets. Any `contentId` set in a request won't be included in a non-atomic batch operation! If `$1` parameter was used outside of Change Set you will get an error similar to the following: `Error identified in Payload provided by the user for Entity :'<entity name>'`.
11581195
1159-
Per batch operation:
1196+
**Per batch operation:**
11601197
11611198
```ts
11621199
const contact = {
@@ -1186,9 +1223,7 @@ const responses = await dynamicsWebApi.executeBatch({
11861223
});
11871224
```
11881225
1189-
**Important!** There seem to be a bug in Dynamics 365 Web Api (Checked: July 16, 2023) where it does not process the last operation in a batch request (Change Sets work fine). As a workaround, you can add any "GET" operation at the end to make it work, like in the following example. Please let me know if this bug was fixed.
1190-
1191-
Per request:
1226+
**Per request:**
11921227
11931228
```ts
11941229
dynamicsWebApi.startBatch();
@@ -1203,19 +1238,12 @@ dynamicsWebApi.create({
12031238
inChangeSet: false //<--- do not include in a change set
12041239
});
12051240

1206-
//this is a workaround to a D365 bug (checked on July 16, 2023)
1207-
dynamicsWebApi.retrieveMutliple({
1208-
collection: "contacts",
1209-
top: 1,
1210-
select: ["firstname"]
1211-
});
1212-
12131241
const responses = await dynamicsWebApi.executeBatch();
12141242
```
12151243
1216-
These two samples do the same thing: make all requests non-atomic.
1244+
The two examples above do the same thing: make all requests non-atomic.
12171245
1218-
By setting `inChangeSet:false` per request gives more control over which operation should be included in a change set and which ones do not, for example:
1246+
By setting `inChangeSet: false` per request gives more control over which operation should be included in a change set and which ones do not, for example:
12191247
12201248
```ts
12211249
dynamicsWebApi.startBatch();
@@ -1279,13 +1307,63 @@ Currently, there are some limitations in DynamicsWebApi Batch Operations:
12791307
* Operations that use pagination to recursively retrieve all records cannot be used in a 'batch mode'. These include: `retrieveAll`, `retrieveAllRequest`, `countAll`, `fetchAll`, `executeFetchXmlAll`.
12801308
You will get an error saying that the operation is incompatible with a 'batch mode'.
12811309
1282-
There are also out of the box Web API limitations for batch operations:
1310+
There are also out of the box Dataverse Web API limitations for batch operations:
12831311
12841312
* Batch requests can contain up to 1000 individual requests and cannot contain other batch requests.
12851313
* Not supported in Microsoft Power Pages. (checked June 2024)
12861314
12871315
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).
12881316
1317+
1318+
#### returnRepresentation with expand throws an error
1319+
`checked: Feb 2025`
1320+
1321+
The Dataverse Web API seems to have a limitation (or a bug) where it does not return the response with `returnRepresentation` set to `true` when `expand` is provided with `update` or `upsert` operations. The error itself is also very misleading:
1322+
1323+
```
1324+
...the entity with a name = '<entity name>' with namemapping = 'logical' was not found in the MetadataCache.LazyDynamicMetadataCache...
1325+
```
1326+
1327+
As a workaround here, remove `returnRepresentation` from `update` or `upsert` and add a `retrieve` operation that returns a recently created/updated table with an `expand` at the end. This does not seem to impact a `create` operation.
1328+
1329+
Example:
1330+
1331+
```ts
1332+
const accountId = "71d78e22-e238-4811-b5df-b4854088819a";
1333+
1334+
dynamicsWebApi.startBatch();
1335+
1336+
dynamicsWebApi.update({
1337+
collection: "accounts",
1338+
key: accountId,
1339+
data: {
1340+
name: "Account Name",
1341+
}
1342+
//adding the following parameters will throw an error (because of expand)
1343+
//returnRepresentation: true,
1344+
//select: ["name"],
1345+
//expand: [{
1346+
// property: "primarycontactid",
1347+
// select: ["firstname"]
1348+
//}]
1349+
});
1350+
1351+
//a workaround
1352+
dynamicsWebApi.retrieve({
1353+
collection: "accounts",
1354+
key: accountId,
1355+
select: ["name"],
1356+
expand: [{
1357+
property: "primarycontactid",
1358+
select: ["firstname"]
1359+
}]
1360+
});
1361+
1362+
const results = await dynamicsWebApi.executeBatch();
1363+
//results[0] will be "true"
1364+
//results[1] will be a retrieved record object
1365+
```
1366+
12891367
## Work with Table Definitions (Entity Metadata)
12901368
12911369
Before working with metadata read [the following section from Microsoft Documentation](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/query-metadata-web-api).
@@ -2554,4 +2632,4 @@ And if you would like to contribute to the project you may do it in multiple way
25542632
gets improved and all raised tickets have been answered and fixed in a short amount of time. If you feel that this project has saved your time and you would like to support it,
25552633
then please feel free to use PayPal or GitHub Sponsors. My PayPal button: [![PayPal.Me](/.github/extra/paypal.png)](https://paypal.me/alexrogov), GitHub button can be found on the project's page.
25562634
2557-
All contributions are greatly appreciated!
2635+
All contributions are greatly appreciated!

0 commit comments

Comments
 (0)