Skip to content

Commit 53daa42

Browse files
remove brackets from guids in filter, upd. readme
1 parent 636ba57 commit 53daa42

File tree

3 files changed

+46
-9
lines changed

3 files changed

+46
-9
lines changed

README.md

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function acquireToken(dynamicsWebApiCallback){
120120

121121
//create DynamicsWebApi object
122122
var dynamicsWebApi = new DynamicsWebApi({
123-
webApiUrl: 'https://myorg.api.crm.dynamics.com/api/data/v9.0/',
123+
webApiUrl: 'https:/myorg.api.crm.dynamics.com/api/data/v9.0/',
124124
onTokenRefresh: acquireToken
125125
});
126126

@@ -192,20 +192,20 @@ async | Boolean | All | **Important! XHR requests only!** Indicates whether the
192192
collection | String | All | The name of the Entity Collection (or Entity Logical name in `v1.4.0+`).
193193
count | Boolean | `retrieveMultipleRequest`, `retrieveAllRequest` | Boolean that sets the $count system query option with a value of true to include a count of entities that match the filter criteria up to 5000 (per page). Do not use $top with $count!
194194
duplicateDetection | Boolean | `createRequest`, `updateRequest`, `upsertRequest` | `v.1.3.4+` **Web API v9+ only!** Boolean that enables duplicate detection. [More info](https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/webapi/update-delete-entities-using-web-api#check-for-duplicate-records)
195-
entity | Object | `updateRequest`, `upsertRequest` | A JavaScript object with properties corresponding to the logical name of entity attributes (exceptions are lookups and single-valued navigation properties).
196-
expand | Array | `retrieveRequest`, `updateRequest`, `upsertRequest` | An array of Expand Objects (described below the table) representing the $expand OData System Query Option value to control which related records are also returned.
195+
entity | Object | `createRequest`, `updateRequest`, `upsertRequest` | A JavaScript object with properties corresponding to the logical name of entity attributes (exceptions are lookups and single-valued navigation properties).
196+
expand | Array | `retrieveRequest`, `createRequest`, `updateRequest`, `upsertRequest` | An array of Expand Objects (described below the table) representing the $expand OData System Query Option value to control which related records are also returned.
197197
filter | String | `retrieveRequest`, `retrieveMultipleRequest`, `retrieveAllRequest` | Use the $filter system query option to set criteria for which entities will be returned.
198-
id | String | `retrieveRequest`, `updateRequest`, `upsertRequest`, `deleteRequest` | `deprecated in v.1.3.4` Use `key` field, instead of `id`. A String representing the Primary Key (GUID) of the record.
198+
id | String | `retrieveRequest`, `createRequest`, `updateRequest`, `upsertRequest`, `deleteRequest` | `deprecated in v.1.3.4` Use `key` field, instead of `id`. A String representing the Primary Key (GUID) of the record.
199199
ifmatch | String | `retrieveRequest`, `updateRequest`, `upsertRequest`, `deleteRequest` | Sets If-Match header value that enables to use conditional retrieval or optimistic concurrency in applicable requests. [More info](https://msdn.microsoft.com/en-us/library/mt607711.aspx).
200200
ifnonematch | String | `retrieveRequest`, `upsertRequest` | Sets If-None-Match header value that enables to use conditional retrieval in applicable requests. [More info](https://msdn.microsoft.com/en-us/library/mt607711.aspx).
201201
impersonate | String | All | A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user.
202-
includeAnnotations | String | `retrieveRequest`, `retrieveMultipleRequest`, `retrieveAllRequest`, `updateRequest`, `upsertRequest` | Sets Prefer header with value "odata.include-annotations=" and the specified annotation. Annotations provide additional information about lookups, options sets and other complex attribute types.
203-
key | String | `retrieveRequest`, `updateRequest`, `upsertRequest`, `deleteRequest` | `v.1.3.4+` A String representing collection record's Primary Key (GUID) or Alternate Key(s).
202+
includeAnnotations | String | `retrieveRequest`, `retrieveMultipleRequest`, `retrieveAllRequest`, `createRequest`, `updateRequest`, `upsertRequest` | Sets Prefer header with value "odata.include-annotations=" and the specified annotation. Annotations provide additional information about lookups, options sets and other complex attribute types.
203+
key | String | `retrieveRequest`, `createRequest`, `updateRequest`, `upsertRequest`, `deleteRequest` | `v.1.3.4+` A String representing collection record's Primary Key (GUID) or Alternate Key(s).
204204
maxPageSize | Number | `retrieveMultipleRequest`, `retrieveAllRequest` | Sets the odata.maxpagesize preference value to request the number of entities returned in the response.
205205
navigationProperty | String | `retrieveRequest` | A String representing the name of a single-valued navigation property. Useful when needed to retrieve information about a related record in a single request.
206206
noCache | Boolean | All | `v.1.4.0+` If set to `true`, DynamicsWebApi adds a request header `Cache-Control: no-cache`. Default value is `false`.
207207
orderBy | Array | `retrieveMultipleRequest`, `retrieveAllRequest` | An Array (of Strings) representing the order in which items are returned using the $orderby system query option. Use the asc or desc suffix to specify ascending or descending order respectively. The default is ascending if the suffix isn't applied.
208-
returnRepresentation | Boolean | `updateRequest`, `upsertRequest` | Sets Prefer header request with value "return=representation". Use this property to return just created or updated entity in a single request.
208+
returnRepresentation | Boolean | `createRequest`, `updateRequest`, `upsertRequest` | Sets Prefer header request with value "return=representation". Use this property to return just created or updated entity in a single request.
209209
savedQuery | String | `retrieveRequest` | A String representing the GUID value of the saved query.
210210
select | Array | `retrieveRequest`, `retrieveMultipleRequest`, `retrieveAllRequest`, `updateRequest`, `upsertRequest` | An Array (of Strings) representing the $select OData System Query Option to control which attributes will be returned.
211211
token | String | All | Authorization Token. If set, onTokenRefresh will not be called.
@@ -279,6 +279,32 @@ dynamicsWebApi.create(lead, "leads", "return=representation,odata.include-annota
279279
dynamicsWebApi.create(lead, "leads", ["return=representation", "odata.include-annotations=*"], ["subject"]) //...
280280
```
281281

282+
#### Advanced using Request Object
283+
284+
```js
285+
//initialize a CRM entity record object
286+
var lead = {
287+
subject: "Test WebAPI",
288+
firstname: "Test",
289+
lastname: "WebAPI",
290+
jobtitle: "Title"
291+
};
292+
293+
var request = {
294+
collection: "leads",
295+
entity: lead,
296+
returnRepresentation: true
297+
}
298+
299+
//call dynamicsWebApi.createRequest function
300+
dynamicsWebApi.createRequest(request).then(function (record) {
301+
//do something with a record here
302+
var subject = record.subject;
303+
}).catch(function (error) {
304+
//catch error here
305+
})
306+
```
307+
282308
### Update a record
283309

284310
#### Basic
@@ -507,7 +533,7 @@ dynamicsWebApi.retrieve(leadid, "leads", ["ownerid/$ref"]).then(function (refere
507533

508534
#### Retrieve a related record data using a single-valued navigation property
509535

510-
In order to retrieve a related record by a signle-valued navigation property you need to add a prefix "/" to the __first__ element in a `select` array:
536+
In order to retrieve a related record by a single-valued navigation property you need to add a prefix "/" to the __first__ element in a `select` array:
511537
`select: ["/ownerid", "fullname"]`. The first element must be the name of a [single-valued navigation property](https://msdn.microsoft.com/en-us/library/mt607990.aspx#Anchor_5)
512538
and it must contain a prefix "/"; all other elements in a `select` array will represent attributes of __the related entity__. Examples:
513539

lib/utilities/RequestConverter.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ function convertRequestOptions(request, functionName, url, joinSymbol, config) {
6262

6363
if (request.filter) {
6464
ErrorHelper.stringParameterCheck(request.filter, 'DynamicsWebApi.' + functionName, "request.filter");
65-
requestArray.push("$filter=" + request.filter);
65+
var removeBracketsFromGuidReg = /[^"']{([\w\d]{8}[-]?(?:[\w\d]{4}[-]?){3}[\w\d]{12})}(?:[^"']|$)/g;
66+
var filterResult = request.filter.replace(removeBracketsFromGuidReg, ' $1 ').trim();
67+
requestArray.push("$filter=" + filterResult);
6668
}
6769

6870
if (request.savedQuery) {

tests/common-tests.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,15 @@ describe("RequestConverter.convertRequestOptions -", function () {
376376
expect(result).to.deep.equal({ url: stubUrl, query: "$filter=name eq 'name'", headers: {} });
377377
});
378378

379+
it("filter - remove brackets from guid", function () {
380+
var dwaRequest = {
381+
filter: "name eq 'name' and testid1 eq {0000a000-0000-0000-0000-000000000001} and testid2 eq 0000a000-0000-0000-0000-000000000002 and teststring eq '{0000a000-0000-0000-0000-000000000003}'"
382+
};
383+
384+
var result = RequestConverter.convertRequestOptions(dwaRequest, "", stubUrl);
385+
expect(result).to.deep.equal({ url: stubUrl, query: "$filter=name eq 'name' and testid1 eq 0000a000-0000-0000-0000-000000000001 and testid2 eq 0000a000-0000-0000-0000-000000000002 and teststring eq '{0000a000-0000-0000-0000-000000000003}'", headers: {} });
386+
});
387+
379388
it("ifmatch empty", function () {
380389
var dwaRequest = {
381390
ifmatch: ""

0 commit comments

Comments
 (0)