Skip to content

Commit 5560906

Browse files
changes to allow working with Entity Metadata; fix #23; fix other issues
1 parent 2b40912 commit 5560906

15 files changed

+285
-48
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,13 @@ entity | Object | `createRequest`, `updateRequest`, `upsertRequest` | A JavaScri
196196
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.
198198
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.
199-
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).
199+
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.
202202
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.
203203
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.
205+
mergeLabels | Boolean | `updateRequest` | `v.1.4.2+` **Metadata Update only!** Sets `MSCRM.MergeLabels` header that controls whether to overwrite the existing labels or merge your new label with any existing language labels. [More info](https://msdn.microsoft.com/en-us/library/mt593078.aspx#Update%20entities)
205206
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.
206207
noCache | Boolean | All | `v.1.4.0+` If set to `true`, DynamicsWebApi adds a request header `Cache-Control: no-cache`. Default value is `false`.
207208
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.

dist/dynamics-web-api-callbacks.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -479,18 +479,25 @@ function convertRequestOptions(request, functionName, url, joinSymbol, config) {
479479
}
480480

481481
if (request.entity) {
482-
ErrorHelper.parameterCheck(request.entity, 'DynamicsWebApi.' + functionName, 'request.entity')
482+
ErrorHelper.parameterCheck(request.entity, 'DynamicsWebApi.' + functionName, 'request.entity');
483+
484+
483485
}
484486

485487
if (request.data) {
486-
ErrorHelper.parameterCheck(request.data, 'DynamicsWebApi.' + functionName, 'request.data')
488+
ErrorHelper.parameterCheck(request.data, 'DynamicsWebApi.' + functionName, 'request.data');
487489
}
488490

489491
if (request.noCache) {
490492
ErrorHelper.boolParameterCheck(request.noCache, 'DynamicsWebApi.' + functionName, 'request.noCache');
491493
headers['Cache-Control'] = 'no-cache';
492494
}
493495

496+
if (request.mergeLabels){
497+
ErrorHelper.boolParameterCheck(request.mergeLabels, 'DynamicsWebApi.' + functionName, 'request.mergeLabels');
498+
headers['MSCRM.MergeLabels'] = 'true';
499+
}
500+
494501
if (request.expand && request.expand.length) {
495502
ErrorHelper.stringOrArrayParameterCheck(request.expand, 'DynamicsWebApi.' + functionName, "request.expand");
496503
if (typeof request.expand === 'string') {
@@ -785,6 +792,13 @@ function stringifyData(data, config) {
785792
}
786793
}
787794
}
795+
else
796+
if (key.startsWith('oData') ||
797+
key.endsWith('_Formatted') ||
798+
key.endsWith('_NavigationProperty') ||
799+
key.endsWith('_LogicalName')) {
800+
value = undefined;
801+
}
788802

789803
return value;
790804
});
@@ -900,7 +914,9 @@ function _getEntityNames(entityName, config, successCallback, errorCallback) {
900914
}
901915

902916
function _isEntityNameException(entityName) {
903-
var exceptions = ['EntityDefinitions', '$metadata'];
917+
var exceptions = [
918+
'EntityDefinitions', '$metadata', 'RelationshipDefinitions',
919+
'GlobalOptionSetDefinitions', 'ManagedPropertyDefinitions'];
904920

905921
return exceptions.indexOf(entityName) > -1;
906922
}
@@ -1004,6 +1020,7 @@ if (!String.prototype.endsWith || !String.prototype.startsWith) {
10041020
* @property {boolean} noCache - If set to 'true', DynamicsWebApi adds a request header 'Cache-Control: no-cache'. Default value is 'false'.
10051021
* @property {string} savedQuery - A String representing the GUID value of the saved query.
10061022
* @property {string} userQuery - A String representing the GUID value of the user query.
1023+
* @property {boolean} mergeLabels - If set to 'true', DynamicsWebApi adds a request header 'MSCRM.MergeLabels: true'. Default value is 'false'
10071024
*/
10081025

10091026
/**
@@ -1221,7 +1238,10 @@ function DynamicsWebApi(config) {
12211238
}
12221239
};
12231240

1224-
_makeRequest("PATCH", request, 'update', onSuccess, onError);
1241+
//EntityDefinitions cannot be updated using "PATCH" method
1242+
var method = request.collection.indexOf('EntityDefinitions') > -1 ? 'PUT' : 'PATCH';
1243+
1244+
_makeRequest(method, request, 'update', onSuccess, onError);
12251245
}
12261246

12271247
/**
@@ -2001,7 +2021,7 @@ function DynamicsWebApi(config) {
20012021
* Executes an unbound Web API action (not bound to a particular entity record)
20022022
*
20032023
* @param {string} actionName - The name of the Web API action.
2004-
* @param {Object} requestObject - Action request body object.
2024+
* @param {Object} [requestObject] - Action request body object.
20052025
* @param {Function} successCallback - The function that will be passed through and be called by a successful response.
20062026
* @param {Function} errorCallback - The function that will be passed through and be called by a failed response.
20072027
* @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user.
@@ -2016,7 +2036,7 @@ function DynamicsWebApi(config) {
20162036
* @param {string} id - A String representing the GUID value for the record.
20172037
* @param {string} collection - The name of the Entity Collection or Entity Logical name.
20182038
* @param {string} actionName - The name of the Web API action.
2019-
* @param {Object} requestObject - Action request body object.
2039+
* @param {Object} [requestObject] - Action request body object.
20202040
* @param {Function} successCallback - The function that will be passed through and be called by a successful response.
20212041
* @param {Function} errorCallback - The function that will be passed through and be called by a failed response.
20222042
* @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user.
@@ -2146,6 +2166,7 @@ function parseBatchResponse(response) {
21462166

21472167
function populateFormattedValues(object) {
21482168
var keys = Object.keys(object);
2169+
//object._dwa_extendedProperties = [];
21492170

21502171
for (var i = 0; i < keys.length; i++) {
21512172
if (object[keys[i]] != null && object[keys[i]].constructor === Array) {
@@ -2185,6 +2206,7 @@ function populateFormattedValues(object) {
21852206

21862207
if (newKey) {
21872208
object[newKey] = object[keys[i]];
2209+
//object._dwa_extendedProperties.push(newKey);
21882210
}
21892211
}
21902212

@@ -2289,6 +2311,7 @@ var xhrRequest = function (method, uri, data, additionalHeaders, successCallback
22892311
}
22902312
}
22912313
error.status = request.status;
2314+
error.statusText = request.statusText;
22922315
errorCallback(error);
22932316
break;
22942317
}

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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/dynamics-web-api.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,13 @@ function stringifyData(data, config) {
541541
}
542542
}
543543
}
544+
else
545+
if (key.startsWith('oData') ||
546+
key.endsWith('_Formatted') ||
547+
key.endsWith('_NavigationProperty') ||
548+
key.endsWith('_LogicalName')) {
549+
value = undefined;
550+
}
544551

545552
return value;
546553
});
@@ -656,7 +663,9 @@ function _getEntityNames(entityName, config, successCallback, errorCallback) {
656663
}
657664

658665
function _isEntityNameException(entityName) {
659-
var exceptions = ['EntityDefinitions', '$metadata'];
666+
var exceptions = [
667+
'EntityDefinitions', '$metadata', 'RelationshipDefinitions',
668+
'GlobalOptionSetDefinitions', 'ManagedPropertyDefinitions'];
660669

661670
return exceptions.indexOf(entityName) > -1;
662671
}
@@ -759,6 +768,7 @@ if (!String.prototype.endsWith || !String.prototype.startsWith) {
759768
* @property {boolean} noCache - If set to 'true', DynamicsWebApi adds a request header 'Cache-Control: no-cache'. Default value is 'false'.
760769
* @property {string} savedQuery - A String representing the GUID value of the saved query.
761770
* @property {string} userQuery - A String representing the GUID value of the user query.
771+
* @property {boolean} mergeLabels - If set to 'true', DynamicsWebApi adds a request header 'MSCRM.MergeLabels: true'. Default value is 'false'
762772
*/
763773

764774
/**
@@ -1016,9 +1026,12 @@ function DynamicsWebApi(config) {
10161026
request.ifmatch = '*'; //to prevent upsert
10171027
}
10181028

1029+
//EntityDefinitions cannot be updated using "PATCH" method
1030+
var method = request.collection.indexOf('EntityDefinitions') > -1 ? 'PUT' : 'PATCH';
1031+
10191032
//copy locally
10201033
var ifmatch = request.ifmatch;
1021-
return _makeRequest('PATCH', request, 'update')
1034+
return _makeRequest(method, request, 'update')
10221035
.then(function (response) {
10231036
if (response.data) {
10241037
return response.data;
@@ -1643,7 +1656,7 @@ function DynamicsWebApi(config) {
16431656
* Executes an unbound Web API action (not bound to a particular entity record)
16441657
*
16451658
* @param {string} actionName - The name of the Web API action.
1646-
* @param {Object} requestObject - Action request body object.
1659+
* @param {Object} [requestObject] - Action request body object.
16471660
* @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user.
16481661
* @returns {Promise}
16491662
*/
@@ -1657,7 +1670,7 @@ function DynamicsWebApi(config) {
16571670
* @param {string} id - A String representing the GUID value for the record.
16581671
* @param {string} collection - The name of the Entity Collection or Entity Logical name.
16591672
* @param {string} actionName - The name of the Web API action.
1660-
* @param {Object} requestObject - Action request body object.
1673+
* @param {Object} [requestObject] - Action request body object.
16611674
* @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user.
16621675
* @returns {Promise}
16631676
*/
@@ -1781,6 +1794,7 @@ function parseBatchResponse(response) {
17811794

17821795
function populateFormattedValues(object) {
17831796
var keys = Object.keys(object);
1797+
//object._dwa_extendedProperties = [];
17841798

17851799
for (var i = 0; i < keys.length; i++) {
17861800
if (object[keys[i]] != null && object[keys[i]].constructor === Array) {
@@ -1820,6 +1834,7 @@ function populateFormattedValues(object) {
18201834

18211835
if (newKey) {
18221836
object[newKey] = object[keys[i]];
1837+
//object._dwa_extendedProperties.push(newKey);
18231838
}
18241839
}
18251840

@@ -1924,6 +1939,7 @@ var xhrRequest = function (method, uri, data, additionalHeaders, successCallback
19241939
}
19251940
}
19261941
error.status = request.status;
1942+
error.statusText = request.statusText;
19271943
errorCallback(error);
19281944
break;
19291945
}
@@ -2081,18 +2097,25 @@ function convertRequestOptions(request, functionName, url, joinSymbol, config) {
20812097
}
20822098

20832099
if (request.entity) {
2084-
ErrorHelper.parameterCheck(request.entity, 'DynamicsWebApi.' + functionName, 'request.entity')
2100+
ErrorHelper.parameterCheck(request.entity, 'DynamicsWebApi.' + functionName, 'request.entity');
2101+
2102+
20852103
}
20862104

20872105
if (request.data) {
2088-
ErrorHelper.parameterCheck(request.data, 'DynamicsWebApi.' + functionName, 'request.data')
2106+
ErrorHelper.parameterCheck(request.data, 'DynamicsWebApi.' + functionName, 'request.data');
20892107
}
20902108

20912109
if (request.noCache) {
20922110
ErrorHelper.boolParameterCheck(request.noCache, 'DynamicsWebApi.' + functionName, 'request.noCache');
20932111
headers['Cache-Control'] = 'no-cache';
20942112
}
20952113

2114+
if (request.mergeLabels){
2115+
ErrorHelper.boolParameterCheck(request.mergeLabels, 'DynamicsWebApi.' + functionName, 'request.mergeLabels');
2116+
headers['MSCRM.MergeLabels'] = 'true';
2117+
}
2118+
20962119
if (request.expand && request.expand.length) {
20972120
ErrorHelper.stringOrArrayParameterCheck(request.expand, 'DynamicsWebApi.' + functionName, "request.expand");
20982121
if (typeof request.expand === 'string') {

dist/dynamics-web-api.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/dynamics-web-api-callbacks.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ var dwaRequest = function () {
8181
* @property {boolean} noCache - If set to 'true', DynamicsWebApi adds a request header 'Cache-Control: no-cache'. Default value is 'false'.
8282
* @property {string} savedQuery - A String representing the GUID value of the saved query.
8383
* @property {string} userQuery - A String representing the GUID value of the user query.
84+
* @property {boolean} mergeLabels - If set to 'true', DynamicsWebApi adds a request header 'MSCRM.MergeLabels: true'. Default value is 'false'
8485
*/
8586

8687
/**
@@ -298,7 +299,10 @@ function DynamicsWebApi(config) {
298299
}
299300
};
300301

301-
_makeRequest("PATCH", request, 'update', onSuccess, onError);
302+
//EntityDefinitions cannot be updated using "PATCH" method
303+
var method = request.collection.indexOf('EntityDefinitions') > -1 ? 'PUT' : 'PATCH';
304+
305+
_makeRequest(method, request, 'update', onSuccess, onError);
302306
}
303307

304308
/**
@@ -1078,7 +1082,7 @@ function DynamicsWebApi(config) {
10781082
* Executes an unbound Web API action (not bound to a particular entity record)
10791083
*
10801084
* @param {string} actionName - The name of the Web API action.
1081-
* @param {Object} requestObject - Action request body object.
1085+
* @param {Object} [requestObject] - Action request body object.
10821086
* @param {Function} successCallback - The function that will be passed through and be called by a successful response.
10831087
* @param {Function} errorCallback - The function that will be passed through and be called by a failed response.
10841088
* @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user.
@@ -1093,7 +1097,7 @@ function DynamicsWebApi(config) {
10931097
* @param {string} id - A String representing the GUID value for the record.
10941098
* @param {string} collection - The name of the Entity Collection or Entity Logical name.
10951099
* @param {string} actionName - The name of the Web API action.
1096-
* @param {Object} requestObject - Action request body object.
1100+
* @param {Object} [requestObject] - Action request body object.
10971101
* @param {Function} successCallback - The function that will be passed through and be called by a successful response.
10981102
* @param {Function} errorCallback - The function that will be passed through and be called by a failed response.
10991103
* @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user.

lib/dynamics-web-api.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ var dwaRequest = function () {
8181
* @property {boolean} noCache - If set to 'true', DynamicsWebApi adds a request header 'Cache-Control: no-cache'. Default value is 'false'.
8282
* @property {string} savedQuery - A String representing the GUID value of the saved query.
8383
* @property {string} userQuery - A String representing the GUID value of the user query.
84+
* @property {boolean} mergeLabels - If set to 'true', DynamicsWebApi adds a request header 'MSCRM.MergeLabels: true'. Default value is 'false'
8485
*/
8586

8687
/**
@@ -324,6 +325,28 @@ function DynamicsWebApi(config) {
324325
return this.retrieveRequest(request);
325326
};
326327

328+
//this.retrieveAttributes = function (entityDefinitionId, attributeType, select, filter) {
329+
330+
// var navigationProperty = 'Attributes';
331+
332+
// if (attributeType) {
333+
// ErrorHelper.stringParameterCheck(attributeType, "DynamicsWebApi.retrieveAttributes", "attributeType");
334+
// navigationProperty += '/' + attributeType;
335+
// }
336+
337+
// var request = {
338+
// collection: 'EntityDefinitions',
339+
// key: entityDefinitionId,
340+
// navigationProperty: 'Attributes',
341+
// select: select,
342+
// filter: filter
343+
// };
344+
345+
// return this.retrieveRequest(request);
346+
//};
347+
348+
//this.retrieveAttribute = function(entityDefinitionId, attributeId, attributeType, select, expand
349+
327350
/**
328351
* Sends an asynchronous request to update a record.
329352
*
@@ -338,9 +361,12 @@ function DynamicsWebApi(config) {
338361
request.ifmatch = '*'; //to prevent upsert
339362
}
340363

364+
//EntityDefinitions cannot be updated using "PATCH" method
365+
var method = request.collection.indexOf('EntityDefinitions') > -1 ? 'PUT' : 'PATCH';
366+
341367
//copy locally
342368
var ifmatch = request.ifmatch;
343-
return _makeRequest('PATCH', request, 'update')
369+
return _makeRequest(method, request, 'update')
344370
.then(function (response) {
345371
if (response.data) {
346372
return response.data;
@@ -965,7 +991,7 @@ function DynamicsWebApi(config) {
965991
* Executes an unbound Web API action (not bound to a particular entity record)
966992
*
967993
* @param {string} actionName - The name of the Web API action.
968-
* @param {Object} requestObject - Action request body object.
994+
* @param {Object} [requestObject] - Action request body object.
969995
* @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user.
970996
* @returns {Promise}
971997
*/
@@ -979,7 +1005,7 @@ function DynamicsWebApi(config) {
9791005
* @param {string} id - A String representing the GUID value for the record.
9801006
* @param {string} collection - The name of the Entity Collection or Entity Logical name.
9811007
* @param {string} actionName - The name of the Web API action.
982-
* @param {Object} requestObject - Action request body object.
1008+
* @param {Object} [requestObject] - Action request body object.
9831009
* @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user.
9841010
* @returns {Promise}
9851011
*/

0 commit comments

Comments
 (0)