Skip to content

Commit 6f8f568

Browse files
fixes: on-premise service url issue; incomplete type definitions for typescript, inconsistent removing curly brackets for odata.bind actions.
1 parent 351d879 commit 6f8f568

12 files changed

+51
-26
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ contentId | String | `createRequest`, `updateRequest`, `upsertRequest`, `deleteR
235235
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!
236236
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)
237237
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).
238-
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.
238+
expand | Array | `retrieveRequest`, `retrieveMultipleRequest`, `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.
239239
filter | String | `retrieveRequest`, `retrieveMultipleRequest`, `retrieveAllRequest` | Use the $filter system query option to set criteria for which entities will be returned.
240240
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.
241241
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)
@@ -268,9 +268,9 @@ property | String | A name of a single-valued navigation property which needs to
268268
select | Array | An Array (of Strings) representing the $select OData System Query Option to control which attributes will be returned.
269269
top | Number | Limit the number of results returned by using the $top system query option.
270270

271-
According to CRM developers ([here](http://stackoverflow.com/a/34742977/2042071) and [here](https://community.dynamics.com/crm/b/joegilldynamicscrm/archive/2016/03/23/web-api-querying-with-expand)
272-
$expand does not work for retrieveMultiple requests which is claimed as a bug of CRM Web API.
273-
As well as multi-level expands are not implemented yet. This situation may be changed with the future updates in the platform. Please look for the news!
271+
The following seems to be fixed: ~~According to CRM developers ([here](http://stackoverflow.com/a/34742977/2042071) and [here](https://community.dynamics.com/crm/b/joegilldynamicscrm/archive/2016/03/23/web-api-querying-with-expand)
272+
$expand does not work for retrieveMultiple requests which is claimed as a bug of CRM Web API.~~
273+
Unconfirmed: Multi-level expands are not implemented yet. This situation may be changed with the future updates in the platform. Please look for the news!
274274

275275
For complex requests to Web API with multi-level expands use `executeFetchXml` function.
276276

dist/dynamics-web-api-callbacks.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -829,9 +829,16 @@ function stringifyData(data, config) {
829829
}
830830
}
831831

832-
//add full web api url if it's not set
833832
if (!value.startsWith(config.webApiUrl)) {
834-
value = config.webApiUrl + value.replace(/^\\/, '');
833+
//add full web api url if it's not set
834+
if (key.endsWith('@odata.bind')) {
835+
if (!value.startsWith('/')) {
836+
value = '/' + value;
837+
}
838+
}
839+
else {
840+
value = config.webApiUrl + value.replace(/^\//, '');
841+
}
835842
}
836843
}
837844
}
@@ -847,7 +854,7 @@ function stringifyData(data, config) {
847854
});
848855

849856
stringifiedData = stringifiedData.replace(/[\u007F-\uFFFF]/g, function (chr) {
850-
return "\\u" + ("0000" + chr.charCodeAt(0).toString(16)).substr(-4)
857+
return "\\u" + ("0000" + chr.charCodeAt(0).toString(16)).substr(-4);
851858
});
852859
}
853860

@@ -2126,7 +2133,7 @@ function DynamicsWebApi(config) {
21262133
/**
21272134
* Executes a bound Web API action (bound to a particular entity record)
21282135
*
2129-
* @param {string} id - A String representing the GUID value for the record.
2136+
* @param {string} [id] - A String representing the GUID value for the record.
21302137
* @param {string} collection - The name of the Entity Collection or Entity Logical name.
21312138
* @param {string} actionName - The name of the Web API action.
21322139
* @param {Object} [requestObject] - Action request body object.

dist/dynamics-web-api-callbacks.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/dynamics-web-api.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,16 @@ function stringifyData(data, config) {
539539
}
540540
}
541541

542-
//add full web api url if it's not set
543542
if (!value.startsWith(config.webApiUrl)) {
544-
value = config.webApiUrl + value.replace(/^\\/, '');
543+
//add full web api url if it's not set
544+
if (key.endsWith('@odata.bind')) {
545+
if (!value.startsWith('/')) {
546+
value = '/' + value;
547+
}
548+
}
549+
else {
550+
value = config.webApiUrl + value.replace(/^\//, '');
551+
}
545552
}
546553
}
547554
}
@@ -557,7 +564,7 @@ function stringifyData(data, config) {
557564
});
558565

559566
stringifiedData = stringifiedData.replace(/[\u007F-\uFFFF]/g, function (chr) {
560-
return "\\u" + ("0000" + chr.charCodeAt(0).toString(16)).substr(-4)
567+
return "\\u" + ("0000" + chr.charCodeAt(0).toString(16)).substr(-4);
561568
});
562569
}
563570

@@ -1643,7 +1650,7 @@ function DynamicsWebApi(config) {
16431650
/**
16441651
* Executes a bound function
16451652
*
1646-
* @param {string} id - A String representing the GUID value for the record.
1653+
* @param {string} [id] - A String representing the GUID value for the record.
16471654
* @param {string} collection - The name of the Entity Collection or Entity Logical name.
16481655
* @param {string} functionName - The name of the function.
16491656
* @param {Object} [parameters] - Function's input parameters. Example: { param1: "test", param2: 3 }.

dist/dynamics-web-api.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/dynamics-web-api-callbacks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ function DynamicsWebApi(config) {
10951095
/**
10961096
* Executes a bound Web API action (bound to a particular entity record)
10971097
*
1098-
* @param {string} id - A String representing the GUID value for the record.
1098+
* @param {string} [id] - A String representing the GUID value for the record.
10991099
* @param {string} collection - The name of the Entity Collection or Entity Logical name.
11001100
* @param {string} actionName - The name of the Web API action.
11011101
* @param {Object} [requestObject] - Action request body object.

lib/dynamics-web-api.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ function DynamicsWebApi(config) {
903903
/**
904904
* Executes a bound function
905905
*
906-
* @param {string} id - A String representing the GUID value for the record.
906+
* @param {string} [id] - A String representing the GUID value for the record.
907907
* @param {string} collection - The name of the Entity Collection or Entity Logical name.
908908
* @param {string} functionName - The name of the function.
909909
* @param {Object} [parameters] - Function's input parameters. Example: { param1: "test", param2: 3 }.

lib/requests/sendRequest.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,16 @@ function stringifyData(data, config) {
6767
}
6868
}
6969

70-
//add full web api url if it's not set
7170
if (!value.startsWith(config.webApiUrl)) {
72-
value = config.webApiUrl + value.replace(/^\\/, '');
71+
//add full web api url if it's not set
72+
if (key.endsWith('@odata.bind')) {
73+
if (!value.startsWith('/')) {
74+
value = '/' + value;
75+
}
76+
}
77+
else {
78+
value = config.webApiUrl + value.replace(/^\//, '');
79+
}
7380
}
7481
}
7582
}
@@ -85,7 +92,7 @@ function stringifyData(data, config) {
8592
});
8693

8794
stringifiedData = stringifiedData.replace(/[\u007F-\uFFFF]/g, function (chr) {
88-
return "\\u" + ("0000" + chr.charCodeAt(0).toString(16)).substr(-4)
95+
return "\\u" + ("0000" + chr.charCodeAt(0).toString(16)).substr(-4);
8996
});
9097
}
9198

tests/main-tests.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,7 @@ describe("promises -", function () {
11491149
.post("/tests_records/$ref", {
11501150
"@odata.id": mocks.webApiUrl + "records(" + mocks.data.testEntityId2 + ")"
11511151
})
1152-
.reply(response.status, response.responseText, response.responseHeaders)
1152+
.reply(response.status, response.responseText, response.responseHeaders);
11531153
});
11541154

11551155
after(function () {
@@ -1604,7 +1604,7 @@ describe("promises -", function () {
16041604
var response = mocks.responses.basicEmptyResponseSuccess;
16051605
scope = nock(mocks.webApiUrl)
16061606
.post("/FUN", mocks.responses.actionRequestModified)
1607-
.reply(response.status, response.responseText, response.responseHeaders)
1607+
.reply(response.status, response.responseText, response.responseHeaders);
16081608
});
16091609

16101610
after(function () {

tests/stubs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ var responseStubs = {
819819
Status: 3,
820820
OpportunityClose: {
821821
subject: "Won Opportunity",
822-
"[email protected]": webApiUrl + "tests(" + dataStubs.testEntityId + ")"
822+
"[email protected]": "/tests(" + dataStubs.testEntityId + ")"
823823
}
824824
},
825825
upsertPreventCreateResponse: {

types/dynamics-web-api-callbacks.d.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ declare class DynamicsWebApi {
349349
* @param errorCallback - The function that will be passed through and be called by a failed response.
350350
* @param impersonateUserId - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user.
351351
*/
352-
executeBoundAction(id: string, collection: string, actionName: string, requestObject: Object, successCallback: Function, errorCallback: Function, impersonateUserId?: string): void;
352+
executeBoundAction(id?: string, collection: string, actionName: string, requestObject: Object, successCallback: Function, errorCallback: Function, impersonateUserId?: string): void;
353353
/**
354354
* Sends an asynchronous request to create an entity definition.
355355
*
@@ -661,6 +661,8 @@ declare namespace DynamicsWebApi {
661661
}
662662

663663
interface RetrieveMultipleRequest extends Request {
664+
/**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. */
665+
expand?: Expand[];
664666
/**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! */
665667
count?: boolean;
666668
/**Use the $filter system query option to set criteria for which entities will be returned. */

types/dynamics-web-api.d.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ declare class DynamicsWebApi {
291291
* @param requestObject - Action request body object.
292292
* @param impersonateUserId - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user.
293293
*/
294-
executeBoundAction(id: string, collection: string, actionName: string, requestObject?: Object, impersonateUserId?: string): Promise<any>;
294+
executeBoundAction(id?: string, collection: string, actionName: string, requestObject?: Object, impersonateUserId?: string): Promise<any>;
295295
/**
296296
* Sends an asynchronous request to create an entity definition.
297297
*
@@ -481,7 +481,7 @@ declare namespace DynamicsWebApi {
481481
interface CreateRequest extends CRUDRequest {
482482
/**v.1.3.4+ Web API v9+ only! Boolean that enables duplicate detection. */
483483
duplicateDetection?: boolean;
484-
/**A JavaScript object with properties corresponding to the logical name of entity attributes(exceptions are lookups and single - valued navigation properties). */
484+
/**A JavaScript object with properties corresponding to the logical name of entity attributes(exceptions are lookups and single-valued navigation properties). */
485485
entity?: any;
486486
/**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. */
487487
expand?: Expand[];
@@ -500,7 +500,7 @@ declare namespace DynamicsWebApi {
500500
interface UpdateRequestBase extends CRUDRequest {
501501
/**v.1.3.4+ Web API v9+ only! Boolean that enables duplicate detection. */
502502
duplicateDetection?: boolean;
503-
/**A JavaScript object with properties corresponding to the logical name of entity attributes(exceptions are lookups and single - valued navigation properties). */
503+
/**A JavaScript object with properties corresponding to the logical name of entity attributes(exceptions are lookups and single-valued navigation properties). */
504504
entity?: any;
505505
/**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. */
506506
expand?: Expand[];
@@ -565,6 +565,8 @@ declare namespace DynamicsWebApi {
565565
}
566566

567567
interface RetrieveMultipleRequest extends Request {
568+
/**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. */
569+
expand?: Expand[];
568570
/**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! */
569571
count?: boolean;
570572
/**Use the $filter system query option to set criteria for which entities will be returned. */

0 commit comments

Comments
 (0)