diff --git a/dist/dwa.js b/dist/dwa.js index ee002e3..94215b8 100644 --- a/dist/dwa.js +++ b/dist/dwa.js @@ -1,4 +1,4 @@ -/*! dwa v1.4.5 (c) 2018 Aleksandr Rogov */ +/*! dwa v1.4.6 (c) 2018 Aleksandr Rogov */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); diff --git a/dist/dynamics-web-api-callbacks.js b/dist/dynamics-web-api-callbacks.js index 0f8725f..c739b31 100644 --- a/dist/dynamics-web-api-callbacks.js +++ b/dist/dynamics-web-api-callbacks.js @@ -1,4 +1,4 @@ -/*! dynamics-web-api-callbacks v1.4.5 (c) 2018 Aleksandr Rogov */ +/*! dynamics-web-api-callbacks v1.4.6 (c) 2018 Aleksandr Rogov */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); @@ -610,7 +610,7 @@ function convertRequest(request, functionName, config) { } return { url: result.url, headers: result.headers, async: result.async }; -}; +} var RequestConverter = { convertRequestOptions: convertRequestOptions, @@ -625,7 +625,7 @@ module.exports = RequestConverter; function isNull (value) { return typeof value === "undefined" || typeof value === "unknown" || value == null; -}; +} //https://stackoverflow.com/a/8809472 function generateUUID() { // Public Domain/MIT @@ -638,7 +638,7 @@ function generateUUID() { // Public Domain/MIT d = Math.floor(d / 16); return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16); }); -}; +} function getXrmContext() { if (typeof GetGlobalContext != 'undefined') { @@ -657,7 +657,7 @@ function getXrmContext() { } throw new Error('Xrm Context is not available. In most cases, it can be resolved by adding a reference to a ClientGlobalContext.js.aspx. Please refer to MSDN documentation for more details.'); -}; +} function getClientUrl() { var context = getXrmContext(); @@ -672,11 +672,11 @@ function getClientUrl() { } return ''; -}; +} function initWebApiUrl(version) { return getClientUrl() + '/api/data/v' + version + '/'; -}; +} function getXrmInternal() { //todo: Xrm.Internal namespace is not supported @@ -685,7 +685,7 @@ function getXrmInternal() { } return null; -}; +} var Utility = { /** @@ -729,7 +729,7 @@ var Utility = { getClientUrl: getClientUrl, initWebApiUrl: initWebApiUrl -} +}; module.exports = Utility; @@ -1304,9 +1304,11 @@ module.exports = function buildPreferHeader(request, functionName, config) { var includeAnnotations = request.includeAnnotations; var maxPageSize = request.maxPageSize; + var prefer; + if (request.prefer && request.prefer.length) { ErrorHelper.stringOrArrayParameterCheck(request.prefer, "DynamicsWebApi." + functionName, "request.prefer"); - var prefer = request.prefer; + prefer = request.prefer; if (typeof prefer === "string") { prefer = prefer.split(','); } @@ -1324,6 +1326,8 @@ module.exports = function buildPreferHeader(request, functionName, config) { } } + prefer = []; + if (config) { if (returnRepresentation == null) { returnRepresentation = config.returnRepresentation; @@ -1332,8 +1336,6 @@ module.exports = function buildPreferHeader(request, functionName, config) { maxPageSize = maxPageSize ? maxPageSize : config.maxPageSize; } - var prefer = []; - if (returnRepresentation) { ErrorHelper.boolParameterCheck(returnRepresentation, "DynamicsWebApi." + functionName, "request.returnRepresentation"); prefer.push(DWA.Prefer.ReturnRepresentation); @@ -1407,9 +1409,9 @@ module.exports = function getFetchXmlPagingCookie(pageCookies, currentPageNumber cookie: "", page: currentPageNumber, nextPage: currentPageNumber + 1 - } + }; } -} +}; /***/ }), /* 14 */ @@ -1600,7 +1602,7 @@ function DynamicsWebApi(config) { var id = /([0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12})\)$/i.exec(entityUrl)[1]; successCallback(id); } - } + }; _makeRequest("POST", request, 'create', onSuccess, errorCallback); }; @@ -1675,7 +1677,7 @@ function DynamicsWebApi(config) { //copy locally var ifmatch = request.ifmatch; var onError = function (xhr) { - if (ifmatch && xhr.status == 412) { + if (ifmatch && xhr.status === 412) { //precondition failed - not deleted successCallback(false); } @@ -1685,13 +1687,12 @@ function DynamicsWebApi(config) { } }; - //EntityDefinitions cannot be updated using "PATCH" method - var method = request.collection.indexOf('EntityDefinitions') > -1 || - request.collection.indexOf('RelationshipDefinitions') > -1 - ? 'PUT' : 'PATCH'; + //Metadata definitions, cannot be updated using "PATCH" method + var method = /EntityDefinitions|RelationshipDefinitions|GlobalOptionSetDefinitions/.test(request.collection) + ? 'PUT' : 'PATCH'; _makeRequest(method, request, 'update', onSuccess, onError); - } + }; /** * Sends an asynchronous request to update a record. @@ -1790,7 +1791,7 @@ function DynamicsWebApi(config) { */ this.deleteRequest = function (request, successCallback, errorCallback) { - ErrorHelper.parameterCheck(request, "DynamicsWebApi.delete", "request") + ErrorHelper.parameterCheck(request, "DynamicsWebApi.delete", "request"); ErrorHelper.callbackParameterCheck(successCallback, "DynamicsWebApi.delete", "successCallback"); ErrorHelper.callbackParameterCheck(errorCallback, "DynamicsWebApi.delete", "errorCallback"); @@ -1801,7 +1802,7 @@ function DynamicsWebApi(config) { //copy locally var ifmatch = request.ifmatch; var onError = function (xhr) { - if (ifmatch && xhr.status == 412) { + if (ifmatch && xhr.status === 412) { //precondition failed - not deleted successCallback(false); } @@ -1812,7 +1813,7 @@ function DynamicsWebApi(config) { }; _makeRequest('DELETE', request, 'delete', onSuccess, onError); - } + }; /** * Sends an asynchronous request to delete a record. @@ -1857,14 +1858,14 @@ function DynamicsWebApi(config) { */ this.retrieveRequest = function (request, successCallback, errorCallback) { - ErrorHelper.parameterCheck(request, "DynamicsWebApi.retrieve", "request") + ErrorHelper.parameterCheck(request, "DynamicsWebApi.retrieve", "request"); ErrorHelper.callbackParameterCheck(successCallback, "DynamicsWebApi.retrieve", "successCallback"); ErrorHelper.callbackParameterCheck(errorCallback, "DynamicsWebApi.retrieve", "errorCallback"); //copy locally var select = request.select; var onSuccess = function (response) { - if (select != null && select.length == 1 && select[0].endsWith("/$ref") && response.data["@odata.id"] != null) { + if (select != null && select.length === 1 && select[0].endsWith("/$ref") && response.data["@odata.id"] != null) { successCallback(Utility.convertToReferenceObject(response.data)); } else { @@ -1873,7 +1874,7 @@ function DynamicsWebApi(config) { }; _makeRequest('GET', request, 'retrieve', onSuccess, errorCallback); - } + }; /** * Sends an asynchronous request to retrieve a record. @@ -1888,7 +1889,7 @@ function DynamicsWebApi(config) { this.retrieve = function (key, collection, successCallback, errorCallback, select, expand) { ErrorHelper.stringParameterCheck(key, "DynamicsWebApi.retrieve", "key"); - key = ErrorHelper.keyParameterCheck(key, "DynamicsWebApi.retrieve", "key") + key = ErrorHelper.keyParameterCheck(key, "DynamicsWebApi.retrieve", "key"); ErrorHelper.stringParameterCheck(collection, "DynamicsWebApi.retrieve", "collection"); ErrorHelper.callbackParameterCheck(successCallback, "DynamicsWebApi.retrieve", "successCallback"); ErrorHelper.callbackParameterCheck(errorCallback, "DynamicsWebApi.retrieve", "errorCallback"); @@ -1945,11 +1946,11 @@ function DynamicsWebApi(config) { }; var onError = function (xhr) { - if (ifnonematch && xhr.status == 412) { + if (ifnonematch && xhr.status === 412) { //if prevent update successCallback(); } - else if (ifmatch && xhr.status == 404) { + else if (ifmatch && xhr.status === 404) { //if prevent create successCallback(); } @@ -1960,7 +1961,7 @@ function DynamicsWebApi(config) { }; _makeRequest('PATCH', request, 'upsert', onSuccess, onError); - } + }; /** * Sends an asynchronous request to upsert a record. @@ -1976,7 +1977,7 @@ function DynamicsWebApi(config) { this.upsert = function (key, collection, object, successCallback, errorCallback, prefer, select) { ErrorHelper.stringParameterCheck(key, "DynamicsWebApi.upsert", "key"); - key = ErrorHelper.keyParameterCheck(key, "DynamicsWebApi.upsert", "key") + key = ErrorHelper.keyParameterCheck(key, "DynamicsWebApi.upsert", "key"); ErrorHelper.parameterCheck(object, "DynamicsWebApi.upsert", "object"); ErrorHelper.stringParameterCheck(collection, "DynamicsWebApi.upsert", "collection"); @@ -2001,7 +2002,7 @@ function DynamicsWebApi(config) { }; this.upsertRequest(request, successCallback, errorCallback); - } + }; /** * Sends an asynchronous request to count records. IMPORTANT! The count value does not represent the total number of entities in the system. It is limited by the maximum number of entities that can be returned. Returns: Number @@ -2029,10 +2030,10 @@ function DynamicsWebApi(config) { navigationProperty: '$count' }; - _makeRequest('GET', request, 'count', onSuccess, errorCallback) + _makeRequest('GET', request, 'count', onSuccess, errorCallback); } else { - return this.retrieveMultipleRequest({ + this.retrieveMultipleRequest({ collection: collection, filter: filter, count: true @@ -2040,7 +2041,7 @@ function DynamicsWebApi(config) { successCallback(response.oDataCount ? response.oDataCount : 0); }, errorCallback); } - } + }; /** * Sends an asynchronous request to count records. Returns: Number @@ -2052,7 +2053,7 @@ function DynamicsWebApi(config) { * @param {Array} [select] - An Array representing the $select Query Option to control which attributes will be returned. */ this.countAll = function (collection, successCallback, errorCallback, filter, select) { - return this.retrieveAllRequest({ + this.retrieveAllRequest({ collection: collection, filter: filter, select: select @@ -2061,26 +2062,26 @@ function DynamicsWebApi(config) { ? (response.value ? response.value.length : 0) : 0); }, errorCallback); - } + }; /** * Sends an asynchronous request to retrieve records. * * @param {string} collection - The name of the Entity Collection or Entity Logical name. - * @param {Array} [select] - Use the $select system query option to limit the properties returned. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. + * @param {Array} [select] - Use the $select system query option to limit the properties returned. * @param {string} [filter] - Use the $filter system query option to set criteria for which entities will be returned. * @param {string} [nextPageLink] - Use the value of the @odata.nextLink property with a new GET request to return the next page of data. Pass null to retrieveMultipleOptions. */ this.retrieveMultiple = function (collection, successCallback, errorCallback, select, filter, nextPageLink) { - return this.retrieveMultipleRequest({ + this.retrieveMultipleRequest({ collection: collection, select: select, filter: filter }, successCallback, errorCallback, nextPageLink); - } + }; /** * Sends an asynchronous request to retrieve all records. @@ -2092,12 +2093,12 @@ function DynamicsWebApi(config) { * @param {string} [filter] - Use the $filter system query option to set criteria for which entities will be returned. */ this.retrieveAll = function (collection, successCallback, errorCallback, select, filter) { - return _retrieveAllRequest({ + _retrieveAllRequest({ collection: collection, select: select, filter: filter }, successCallback, errorCallback); - } + }; var retrieveMultipleRequest = function (request, successCallback, errorCallback, nextPageLink) { @@ -2121,7 +2122,7 @@ function DynamicsWebApi(config) { }; _makeRequest('GET', request, 'retrieveMultiple', onSuccess, errorCallback); - } + }; /** * Sends an asynchronous request to retrieve records. @@ -2135,7 +2136,7 @@ function DynamicsWebApi(config) { var _retrieveAllRequest = function (request, successCallback, errorCallback, nextPageLink, records) { - var records = records || []; + records = records || []; var internalSuccessCallback = function (response) { records = records.concat(response.value); @@ -2160,7 +2161,7 @@ function DynamicsWebApi(config) { */ this.retrieveAllRequest = function (request, successCallback, errorCallback) { _retrieveAllRequest(request, successCallback, errorCallback); - } + }; var executeFetchXml = function (collection, fetchXml, successCallback, errorCallback, includeAnnotations, pageNumber, pagingCookie, impersonateUserId) { @@ -2186,9 +2187,7 @@ function DynamicsWebApi(config) { collection: collection, includeAnnotations: includeAnnotations, impersonate: impersonateUserId, - fetchXml: fetchXml, - impersonate: impersonateUserId, - includeAnnotations: includeAnnotations + fetchXml: fetchXml }; var onSuccess = function (response) { @@ -2200,7 +2199,7 @@ function DynamicsWebApi(config) { }; _makeRequest('GET', request, 'executeFetchXml', onSuccess, errorCallback); - } + }; /** * Sends an asynchronous request to count records. Returns: DWA.Types.FetchXmlResponse @@ -2231,7 +2230,7 @@ function DynamicsWebApi(config) { this.executeFetchXml = executeFetchXml; var _executeFetchXmlAll = function (collection, fetchXml, successCallback, errorCallback, includeAnnotations, pageNumber, pagingCookie, impersonateUserId, records) { - var records = records || []; + records = records || []; var internalSuccessCallback = function (response) { records = records.concat(response.value); @@ -2245,11 +2244,11 @@ function DynamicsWebApi(config) { }; executeFetchXml(collection, fetchXml, internalSuccessCallback, errorCallback, includeAnnotations, pageNumber, pagingCookie, impersonateUserId); - } + }; var innerExecuteFetchXmlAll = function (collection, fetchXml, successCallback, errorCallback, includeAnnotations, impersonateUserId) { - return _executeFetchXmlAll(collection, fetchXml, successCallback, errorCallback, includeAnnotations, null, null, impersonateUserId); - } + _executeFetchXmlAll(collection, fetchXml, successCallback, errorCallback, includeAnnotations, null, null, impersonateUserId); + }; /** * Sends an asynchronous request to execute FetchXml to retrieve all records. @@ -2310,7 +2309,7 @@ function DynamicsWebApi(config) { }; _makeRequest('POST', request, 'associate', onSuccess, errorCallback); - } + }; /** * Disassociate for a collection-valued navigation property. @@ -2340,11 +2339,11 @@ function DynamicsWebApi(config) { _additionalUrl: relationshipName + '(' + relatedKey + ')/$ref', collection: collection, key: primaryKey, - impersonate: impersonateUserId, + impersonate: impersonateUserId }; _makeRequest('DELETE', request, 'disassociate', onSuccess, errorCallback); - } + }; /** * Associate for a single-valued navigation property. (1:N) @@ -2381,7 +2380,7 @@ function DynamicsWebApi(config) { }; _makeRequest('PUT', request, 'associateSingleValued', onSuccess, errorCallback); - } + }; /** * Removes a reference to an entity for a single-valued navigation property. (1:N) @@ -2405,7 +2404,7 @@ function DynamicsWebApi(config) { _additionalUrl: singleValuedNavigationPropertyName + "/$ref", key: key, collection: collection, - impersonate: impersonateUserId, + impersonate: impersonateUserId }; var onSuccess = function () { @@ -2413,20 +2412,20 @@ function DynamicsWebApi(config) { }; _makeRequest('DELETE', request, 'disassociateSingleValued', onSuccess, errorCallback); - } + }; /** * Executes an unbound function (not bound to a particular entity record) * * @param {string} functionName - The name of the function. - * @param {Object} [parameters] - Function's input parameters. Example: { param1: "test", param2: 3 }. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. + * @param {Object} [parameters] - Function's input parameters. Example: { param1: "test", param2: 3 }. * @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user. */ this.executeUnboundFunction = function (functionName, successCallback, errorCallback, parameters, impersonateUserId) { - return _executeFunction(functionName, parameters, null, null, successCallback, errorCallback, impersonateUserId, true); - } + _executeFunction(functionName, parameters, null, null, successCallback, errorCallback, impersonateUserId, true); + }; /** * Executes a bound function @@ -2440,8 +2439,8 @@ function DynamicsWebApi(config) { * @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user. */ this.executeBoundFunction = function (id, collection, functionName, successCallback, errorCallback, parameters, impersonateUserId) { - return _executeFunction(functionName, parameters, collection, id, successCallback, errorCallback, impersonateUserId); - } + _executeFunction(functionName, parameters, collection, id, successCallback, errorCallback, impersonateUserId); + }; var _executeFunction = function (functionName, parameters, collection, id, successCallback, errorCallback, impersonateUserId, isUnbound) { @@ -2454,7 +2453,7 @@ function DynamicsWebApi(config) { _unboundRequest: isUnbound, key: id, collection: collection, - impersonate: impersonateUserId, + impersonate: impersonateUserId }; var onSuccess = function (response) { @@ -2464,7 +2463,7 @@ function DynamicsWebApi(config) { }; _makeRequest('GET', request, 'executeFunction', onSuccess, errorCallback); - } + }; /** * Executes an unbound Web API action (not bound to a particular entity record) @@ -2476,8 +2475,8 @@ function DynamicsWebApi(config) { * @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user. */ this.executeUnboundAction = function (actionName, requestObject, successCallback, errorCallback, impersonateUserId) { - return _executeAction(actionName, requestObject, null, null, successCallback, errorCallback, impersonateUserId, true); - } + _executeAction(actionName, requestObject, null, null, successCallback, errorCallback, impersonateUserId, true); + }; /** * Executes a bound Web API action (bound to a particular entity record) @@ -2491,8 +2490,8 @@ function DynamicsWebApi(config) { * @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user. */ this.executeBoundAction = function (id, collection, actionName, requestObject, successCallback, errorCallback, impersonateUserId) { - return _executeAction(actionName, requestObject, collection, id, successCallback, errorCallback, impersonateUserId); - } + _executeAction(actionName, requestObject, collection, id, successCallback, errorCallback, impersonateUserId); + }; var _executeAction = function (actionName, requestObject, collection, id, successCallback, errorCallback, impersonateUserId, isUnbound) { @@ -2724,7 +2723,6 @@ function DynamicsWebApi(config) { * @param {string} relationshipDefinition - Relationship Definition. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. - * @returns {Promise} */ this.createRelationship = function (relationshipDefinition, successCallback, errorCallback) { @@ -2744,8 +2742,8 @@ function DynamicsWebApi(config) { * @param {string} relationshipDefinition - Relationship Definition. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. + * @param {string} [relationshipType] - Use this parameter to cast the Relationship to a specific type. * @param {boolean} [mergeLabels] - Sets MSCRM.MergeLabels header that controls whether to overwrite the existing labels or merge your new label with any existing language labels. Default value is false. - * @returns {Promise} */ this.updateRelationship = function (relationshipDefinition, successCallback, errorCallback, relationshipType, mergeLabels) { @@ -2769,7 +2767,6 @@ function DynamicsWebApi(config) { * @param {string} metadataId - A String representing the GUID value. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. - * @returns {Promise} */ this.deleteRelationship = function (metadataId, successCallback, errorCallback) { ErrorHelper.keyParameterCheck(metadataId, 'DynamicsWebApi.deleteRelationship', 'metadataId'); @@ -2790,7 +2787,6 @@ function DynamicsWebApi(config) { * @param {string} [relationshipType] - Use this parameter to cast a Relationship to a specific type: 1:M or M:M. * @param {Array} [select] - Use the $select system query option to limit the properties returned. * @param {string} [filter] - Use the $filter system query option to set criteria for which relationships will be returned. - * @returns {Promise} */ this.retrieveRelationships = function (successCallback, errorCallback, relationshipType, select, filter) { @@ -2812,7 +2808,6 @@ function DynamicsWebApi(config) { * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. * @param {string} [relationshipType] - Use this parameter to cast a Relationship to a specific type: 1:M or M:M. * @param {Array} [select] - Use the $select system query option to limit the properties returned. - * @returns {Promise} */ this.retrieveRelationship = function (metadataId, successCallback, errorCallback, relationshipType, select) { @@ -2828,11 +2823,111 @@ function DynamicsWebApi(config) { this.retrieveRequest(request, successCallback, errorCallback); }; + /** + * Sends an asynchronous request to create a Global Option Set definition + * + * @param {string} globalOptionSetDefinition - Global Option Set Definition. + * @param {Function} successCallback - The function that will be passed through and be called by a successful response. + * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. + */ + this.createGlobalOptionSet = function (globalOptionSetDefinition, successCallback, errorCallback) { + + ErrorHelper.parameterCheck(globalOptionSetDefinition, 'DynamicsWebApi.createGlobalOptionSet', 'globalOptionSetDefinition'); + + var request = { + collection: 'GlobalOptionSetDefinitions', + entity: globalOptionSetDefinition + }; + + this.createRequest(request, successCallback, errorCallback); + }; + + /** + * Sends an asynchronous request to update a Global Option Set. + * + * @param {string} globalOptionSetDefinition - Global Option Set Definition. + * @param {Function} successCallback - The function that will be passed through and be called by a successful response. + * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. + * @param {boolean} [mergeLabels] - Sets MSCRM.MergeLabels header that controls whether to overwrite the existing labels or merge your new label with any existing language labels. Default value is false. + */ + this.updateGlobalOptionSet = function (globalOptionSetDefinition, successCallback, errorCallback, mergeLabels) { + + ErrorHelper.parameterCheck(globalOptionSetDefinition, 'DynamicsWebApi.updateGlobalOptionSet', 'globalOptionSetDefinition'); + ErrorHelper.guidParameterCheck(globalOptionSetDefinition.MetadataId, 'DynamicsWebApi.updateGlobalOptionSet', 'globalOptionSetDefinition.MetadataId'); + + var request = { + collection: 'GlobalOptionSetDefinitions', + mergeLabels: mergeLabels, + key: globalOptionSetDefinition.MetadataId, + entity: globalOptionSetDefinition + }; + this.updateRequest(request, successCallback, errorCallback); + }; + + /** + * Sends an asynchronous request to delete a Global Option Set. + * + * @param {string} globalOptionSetKey - A String representing the GUID value or Alternate Key (such as Name). + * @param {Function} successCallback - The function that will be passed through and be called by a successful response. + * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. + */ + this.deleteGlobalOptionSet = function (globalOptionSetKey, successCallback, errorCallback) { + ErrorHelper.keyParameterCheck(globalOptionSetKey, 'DynamicsWebApi.deleteGlobalOptionSet', 'globalOptionSetKey'); + + var request = { + collection: 'GlobalOptionSetDefinitions', + key: globalOptionSetKey + }; + + this.deleteRequest(request, successCallback, errorCallback); + }; + + /** + * Sends an asynchronous request to retrieve Global Option Set definitions. + * + * @param {string} globalOptionSetKey - The Global Option Set MetadataID or Alternate Key (such as Name). + * @param {Function} successCallback - The function that will be passed through and be called by a successful response. + * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. + * @param {string} [castType] - Use this parameter to cast a Global Option Set to a specific type. + * @param {Array} [select] - Use the $select system query option to limit the properties returned + */ + this.retrieveGlobalOptionSet = function (globalOptionSetKey, successCallback, errorCallback, castType, select) { + ErrorHelper.keyParameterCheck(globalOptionSetKey, 'DynamicsWebApi.retrieveGlobalOptionSet', 'globalOptionSetKey'); + + var request = { + collection: 'GlobalOptionSetDefinitions', + key: globalOptionSetKey, + navigationProperty: castType, + select: select + }; + + this.retrieveRequest(request, successCallback, errorCallback); + }; + + /** + * Sends an asynchronous request to retrieve Global Option Set definitions. + * + * @param {Function} successCallback - The function that will be passed through and be called by a successful response. + * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. + * @param {string} [castType] - Use this parameter to cast a Global Option Set to a specific type. + * @param {Array} [select] - Use the $select system query option to limit the properties returned + */ + this.retrieveGlobalOptionSets = function (successCallback, errorCallback, castType, select) { + + var request = { + collection: 'GlobalOptionSetDefinitions', + navigationProperty: castType, + select: select + }; + + this.retrieveMultipleRequest(request, successCallback, errorCallback); + }; + /** * Creates a new instance of DynamicsWebApi * * @param {DWAConfig} [config] - configuration object. - * @returns {DynamicsWebApi} + * @returns {DynamicsWebApi} The new instance of a DynamicsWebApi */ this.initializeInstance = function (config) { @@ -2841,8 +2936,8 @@ function DynamicsWebApi(config) { } return new DynamicsWebApi(config); - } -}; + }; +} /** * DynamicsWebApi Utility helper class diff --git a/dist/dynamics-web-api-callbacks.min.js b/dist/dynamics-web-api-callbacks.min.js index b068c6c..987d101 100644 --- a/dist/dynamics-web-api-callbacks.min.js +++ b/dist/dynamics-web-api-callbacks.min.js @@ -1,2 +1,2 @@ -/*! dynamics-web-api-callbacks v1.4.5 (c) 2018 Aleksandr Rogov */ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("DynamicsWebApi",[],t):"object"==typeof exports?exports.DynamicsWebApi=t():e.DynamicsWebApi=t()}(this,function(){return function(e){function t(i){if(a[i])return a[i].exports;var r=a[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var a={};return t.m=e,t.c=a,t.i=function(e){return e},t.d=function(e,a,i){t.o(e,a)||Object.defineProperty(e,a,{configurable:!1,enumerable:!0,get:i})},t.n=function(e){var a=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(a,"a",a),a},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=14)}([function(e,t){var a={Types:{ResponseBase:function(){this.oDataContext=""},Response:function(){a.Types.ResponseBase.call(this),this.value={}},ReferenceResponse:function(){a.Types.ResponseBase.call(this),this.id="",this.collection=""},MultipleResponse:function(){a.Types.ResponseBase.call(this),this.oDataNextLink="",this.oDataCount=0,this.value=[]},FetchXmlResponse:function(){a.Types.ResponseBase.call(this),this.value=[],this.PagingInfo={cookie:"",page:0,nextPage:1}}},Prefer:{ReturnRepresentation:"return=representation",Annotations:{AssociatedNavigationProperty:"Microsoft.Dynamics.CRM.associatednavigationproperty",LookupLogicalName:"Microsoft.Dynamics.CRM.lookuplogicalname",All:"*",FormattedValue:"OData.Community.Display.V1.FormattedValue",FetchXmlPagingCookie:"Microsoft.Dynamics.CRM.fetchxmlpagingcookie"}}};e.exports=a},function(e,t){function a(e,t,a){throw new Error(a?e+" requires the "+t+" parameter to be of type "+a:e+" requires the "+t+" parameter.")}var i={handleErrorResponse:function(e){throw new Error("Error: "+e.status+": "+e.message)},parameterCheck:function(e,t,i,r){void 0!==e&&null!==e&&""!=e||a(t,i,r)},stringParameterCheck:function(e,t,i){"string"!=typeof e&&a(t,i,"String")},arrayParameterCheck:function(e,t,i){e.constructor!==Array&&a(t,i,"Array")},stringOrArrayParameterCheck:function(e,t,i){e.constructor!==Array&&"string"!=typeof e&&a(t,i,"String or Array")},numberParameterCheck:function(e,t,i){if("number"!=typeof e){if("string"==typeof e&&e&&!isNaN(parseInt(e)))return;a(t,i,"Number")}},boolParameterCheck:function(e,t,i){"boolean"!=typeof e&&a(t,i,"Boolean")},guidParameterCheck:function(e,t,i){try{return/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(e)[0]}catch(e){a(t,i,"GUID String")}},keyParameterCheck:function(e,t,r){try{i.stringParameterCheck(e,t,r);var n=/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(e);if(n)return n[0];var c=e.split(",");if(c.length)for(var s=0;sa.length)&&(t=a.length),t-=e.length;var i=a.lastIndexOf(e,t);return i!==-1&&i===t},String.prototype.startsWith=function(e,t){return t=t||0,this.substr(t,e.length)===e}},function(e,t,a){function i(e,t,a,r,s){var o={},l=[];if(r=null!=r?r:"&",e){if(e.navigationProperty){if(n.stringParameterCheck(e.navigationProperty,"DynamicsWebApi."+t,"request.navigationProperty"),a+="/"+e.navigationProperty,e.navigationPropertyKey){a+="("+n.keyParameterCheck(e.navigationPropertyKey,"DynamicsWebApi."+t,"request.navigationPropertyKey")+")"}"Attributes"===e.navigationProperty&&e.metadataAttributeType&&(n.stringParameterCheck(e.metadataAttributeType,"DynamicsWebApi."+t,"request.metadataAttributeType"),a+="/"+e.metadataAttributeType)}if(null!=e.select&&e.select.length&&(n.arrayParameterCheck(e.select,"DynamicsWebApi."+t,"request.select"),"retrieve"==t&&1==e.select.length&&e.select[0].endsWith("/$ref")?a+="/"+e.select[0]:(e.select[0].startsWith("/")&&"retrieve"==t&&(null==e.navigationProperty?a+=e.select.shift():e.select.shift()),e.select.length&&l.push("$select="+e.select.join(",")))),e.filter){n.stringParameterCheck(e.filter,"DynamicsWebApi."+t,"request.filter");for(var u=/[^"']{([\w\d]{8}[-]?(?:[\w\d]{4}[-]?){3}[\w\d]{12})}(?:[^"']|$)/g,p=e.filter;null!==(m=u.exec(p));){m.index===u.lastIndex&®ex.lastIndex++;var y=m[0].endsWith(")")?")":" ";p=p.replace(m[0]," "+m[1]+y)}l.push("$filter="+encodeURIComponent(p))}e.savedQuery&&l.push("savedQuery="+n.guidParameterCheck(e.savedQuery,"DynamicsWebApi."+t,"request.savedQuery")),e.userQuery&&l.push("userQuery="+n.guidParameterCheck(e.userQuery,"DynamicsWebApi."+t,"request.userQuery")),e.count&&(n.boolParameterCheck(e.count,"DynamicsWebApi."+t,"request.count"),l.push("$count="+e.count)),e.top&&e.top>0&&(n.numberParameterCheck(e.top,"DynamicsWebApi."+t,"request.top"),l.push("$top="+e.top)),null!=e.orderBy&&e.orderBy.length&&(n.arrayParameterCheck(e.orderBy,"DynamicsWebApi."+t,"request.orderBy"),l.push("$orderby="+e.orderBy.join(",")));var h=c(e,t,s);if(h.length&&(o.Prefer=h),null!=e.ifmatch&&null!=e.ifnonematch)throw new Error("DynamicsWebApi."+t+". Either one of request.ifmatch or request.ifnonematch parameters should be used in a call, not both.");if(e.ifmatch&&(n.stringParameterCheck(e.ifmatch,"DynamicsWebApi."+t,"request.ifmatch"),o["If-Match"]=e.ifmatch),e.ifnonematch&&(n.stringParameterCheck(e.ifnonematch,"DynamicsWebApi."+t,"request.ifnonematch"),o["If-None-Match"]=e.ifnonematch),e.impersonate&&(n.stringParameterCheck(e.impersonate,"DynamicsWebApi."+t,"request.impersonate"),o.MSCRMCallerID=n.guidParameterCheck(e.impersonate,"DynamicsWebApi."+t,"request.impersonate")),e.token&&(n.stringParameterCheck(e.token,"DynamicsWebApi."+t,"request.token"),o.Authorization="Bearer "+e.token),e.duplicateDetection&&(n.boolParameterCheck(e.duplicateDetection,"DynamicsWebApi."+t,"request.duplicateDetection"),o["MSCRM.SuppressDuplicateDetection"]="false"),e.entity&&n.parameterCheck(e.entity,"DynamicsWebApi."+t,"request.entity"),e.data&&n.parameterCheck(e.data,"DynamicsWebApi."+t,"request.data"),e.noCache&&(n.boolParameterCheck(e.noCache,"DynamicsWebApi."+t,"request.noCache"),o["Cache-Control"]="no-cache"),e.mergeLabels&&(n.boolParameterCheck(e.mergeLabels,"DynamicsWebApi."+t,"request.mergeLabels"),o["MSCRM.MergeLabels"]="true"),e.expand&&e.expand.length)if(n.stringOrArrayParameterCheck(e.expand,"DynamicsWebApi."+t,"request.expand"),"string"==typeof e.expand)l.push("$expand="+e.expand);else{for(var f=[],d=0;d2){var c=i(n[1]);m.isNull(c)||(a=a.replace(r,c+"$2"))}}a.startsWith(t.webApiUrl)||(a=t.webApiUrl+a.replace(/^\\/,""))}}else(e.startsWith("oData")||e.endsWith("_Formatted")||e.endsWith("_NavigationProperty")||e.endsWith("_LogicalName"))&&(a=void 0);return a}),a=a.replace(/[\u007F-\uFFFF]/g,function(e){return"\\u"+("0000"+e.charCodeAt(0).toString(16)).substr(-4)})),a}function c(e,t,i,c,s,o,l,u){s||(s={}),s=r(s);var p=n(c,i);if(t.length>2e3){var y="dwa_batch_"+m.generateUUID(),h=[];h.push("--"+y),h.push("Content-Type: application/http"),h.push("Content-Transfer-Encoding: binary\n"),h.push(e+" "+i.webApiUrl+t+" HTTP/1.1");for(var f in s)h.push(f+": "+s[f]),"Authorization"!=f&&delete s[f];h.push("\n--"+y+"--"),p=h.join("\n"),s=r(s),s["Content-Type"]="multipart/mixed;boundary="+y,t="$batch",e="POST"}i.impersonate&&!s.MSCRMCallerID&&(s.MSCRMCallerID=i.impersonate);var d;d=a(9);var b=function(a){a&&(s||(s={}),s.Authorization="Bearer "+(a.hasOwnProperty("accessToken")?a.accessToken:a)),d(e,i.webApiUrl+t,p,s,o,l,u)};i.onTokenRefresh&&(!s||s&&!s.Authorization)?i.onTokenRefresh(b):b()}function s(e,t,a,r){var n=function(t){p={};for(var r=0;r-1}function l(e,t,a,r){if(o(e)||m.isNull(e))return void a(e);if(e=e.toLowerCase(),!t.useEntityNames)return void a(e);try{var n=i(e);m.isNull(n)?s(e,t,a,r):a(n)}catch(e){r({message:"Unable to fetch Collection Names. Error: "+e.message})}}function u(e,t,a,i,r,n){var s=function(s){t.collection=s;var o=y.convertRequest(t,a,i);c(e,o.url,i,t.data||t.entity,o.headers,r,n,o.async)};l(t.collection,i,s,n)}var p,m=(a(0),a(4)),y=a(3);e.exports={sendRequest:c,makeRequest:u,getCollectionName:i}},function(e,t){e.exports=function(e,t){var a;return"string"==typeof t&&(a=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:Z|[-+]\d{2}:\d{2})$/.exec(t))?new Date(Date.UTC(+a[1],+a[2]-1,+a[3],+a[4],+a[5],+a[6])):t}},function(e,t,a){function i(e){var t=e.substr(0,e.indexOf("\r\n")),a=e.split(t);a.shift(),a.pop();for(var i=[],r=0;r-1?i(e)[0]:JSON.parse(e,s),t=n(t)),t}},function(e,t){e.exports=function(e){var t={};if(!e)return t;for(var a=e.split("\r\n"),i=0,r=a.length;i0&&(t[n.substring(0,c)]=n.substring(c+2))}return t}},function(e,t,a){var i=a(7),r=a(8),n=function(e,t,a,n,c,s,o){var l=new XMLHttpRequest;l.open(e,t,o);for(var u in n)l.setRequestHeader(u,n[u]);l.onreadystatechange=function(){if(4===l.readyState){switch(l.status){case 200:case 201:case 204:case 304:c({data:i(l.responseText),headers:r(l.getAllResponseHeaders()),status:l.status});break;default:var e;try{e=JSON.parse(l.response).error}catch(t){e=l.response.length>0?{message:l.response}:{message:"Unexpected Error"}}e.status=l.status,e.statusText=l.statusText,s(e)}l=null}},l.onerror=function(){s({message:"Network Error"}),l=null},l.ontimeout=function(e){s({message:"Request Timed Out"}),l=null},a?l.send(a):l.send()};e.exports=n},function(e,t){e.exports=function(e){if(e){for(var t=Object.keys(e),a="",i="",r=1;r<=t.length;r++){var n=t[r-1],c=e[n];r>1&&(a+=",",i+="&"),a+=n+"=@p"+r,i+="@p"+r+"="+("string"==typeof c?"'"+c+"'":c)}return"("+a+")?"+i}return"()"}},function(e,t,a){var i=a(0),r=a(1);e.exports=function(e,t,a){var n=e.returnRepresentation,c=e.includeAnnotations,s=e.maxPageSize;if(e.prefer&&e.prefer.length){r.stringOrArrayParameterCheck(e.prefer,"DynamicsWebApi."+t,"request.prefer");var o=e.prefer;"string"==typeof o&&(o=o.split(","));for(var l in o){var u=o[l].trim();u===i.Prefer.ReturnRepresentation?n=!0:u.startsWith("odata.include-annotations=")?c=u.replace("odata.include-annotations=","").replace(/"/g,""):u.startsWith("odata.maxpagesize=")&&(s=u.replace("odata.maxpagesize=","").replace(/"/g,""))}}a&&(null==n&&(n=a.returnRepresentation),c=c?c:a.includeAnnotations,s=s?s:a.maxPageSize);var o=[];return n&&(r.boolParameterCheck(n,"DynamicsWebApi."+t,"request.returnRepresentation"),o.push(i.Prefer.ReturnRepresentation)),c&&(r.stringParameterCheck(c,"DynamicsWebApi."+t,"request.includeAnnotations"),o.push('odata.include-annotations="'+c+'"')),s&&s>0&&(r.numberParameterCheck(s,"DynamicsWebApi."+t,"request.maxPageSize"),o.push("odata.maxpagesize="+s)),o.join(",")}},function(e,t){e.exports=function(e){var t=/\/(\w+)\(([0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12})/i.exec(e["@odata.id"]);return{id:t[2],collection:t[1],oDataContext:e["@odata.context"]}}},function(e,t){e.exports=function(e,t){e=e?e:"",t=t?t:1,e=unescape(unescape(e));var a=/pagingcookie="()/.exec(e);if(null!=a){var i=parseInt(a[2]);return{cookie:a[1].replace(//g,">").replace(/\"/g,"'").replace(/\'/g,"""),page:i,nextPage:i+1}}return{cookie:"",page:t,nextPage:t+1}}},function(e,t,a){function i(e){var t={webApiVersion:"8.0",webApiUrl:"",impersonate:null,onTokenRefresh:null,includeAnnotations:null,maxPageSize:null,returnRepresentation:null};e||(e=t),this.setConfig=function(e){e.webApiVersion&&(c.stringParameterCheck(e.webApiVersion,"DynamicsWebApi.setConfig","config.webApiVersion"),t.webApiVersion=e.webApiVersion),e.webApiUrl?(c.stringParameterCheck(e.webApiUrl,"DynamicsWebApi.setConfig","config.webApiUrl"),t.webApiUrl=e.webApiUrl):t.webApiUrl=n.initWebApiUrl(t.webApiVersion),e.impersonate&&(t.impersonate=c.guidParameterCheck(e.impersonate,"DynamicsWebApi.setConfig","config.impersonate")),e.onTokenRefresh&&(c.callbackParameterCheck(e.onTokenRefresh,"DynamicsWebApi.setConfig","config.onTokenRefresh"),t.onTokenRefresh=e.onTokenRefresh),e.includeAnnotations&&(c.stringParameterCheck(e.includeAnnotations,"DynamicsWebApi.setConfig","config.includeAnnotations"),t.includeAnnotations=e.includeAnnotations),e.maxPageSize&&(c.numberParameterCheck(e.maxPageSize,"DynamicsWebApi.setConfig","config.maxPageSize"),t.maxPageSize=e.maxPageSize),e.returnRepresentation&&(c.boolParameterCheck(e.returnRepresentation,"DynamicsWebApi.setConfig","config.returnRepresentation"),t.returnRepresentation=e.returnRepresentation),e.useEntityNames&&(c.boolParameterCheck(e.useEntityNames,"DynamicsWebApi.setConfig","config.useEntityNames"),t.useEntityNames=e.useEntityNames)},this.setConfig(e);var a=function(e,a,i,r,n){s.makeRequest(e,a,i,t,r,n)};this.createRequest=function(e,t,i){c.parameterCheck(e,"DynamicsWebApi.create","request"),c.callbackParameterCheck(t,"DynamicsWebApi.create","successCallback"),c.callbackParameterCheck(i,"DynamicsWebApi.create","errorCallback"),a("POST",e,"create",function(e){if(e.data)t(e.data);else{var a=e.headers["OData-EntityId"]?e.headers["OData-EntityId"]:e.headers["odata-entityid"];t(/([0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12})\)$/i.exec(a)[1])}},i)},this.create=function(e,t,a,i,r,n){c.parameterCheck(e,"DynamicsWebApi.create","object"),c.stringParameterCheck(t,"DynamicsWebApi.create","collection"),r&&c.stringOrArrayParameterCheck(r,"DynamicsWebApi.create","prefer"),n&&c.arrayParameterCheck(n,"DynamicsWebApi.create","select");var s={collection:t,select:n,prefer:r,entity:e};this.createRequest(s,a,i)},this.updateRequest=function(e,t,i){c.parameterCheck(e,"DynamicsWebApi.update","request"),c.callbackParameterCheck(t,"DynamicsWebApi.update","successCallback"),c.callbackParameterCheck(i,"DynamicsWebApi.update","errorCallback"),null==e.ifmatch&&(e.ifmatch="*");var r=function(e){t(e.data?e.data:!0)},n=e.ifmatch,s=function(e){n&&412==e.status?t(!1):i(e)};a(e.collection.indexOf("EntityDefinitions")>-1||e.collection.indexOf("RelationshipDefinitions")>-1?"PUT":"PATCH",e,"update",r,s)},this.update=function(e,t,a,i,r,n,s){c.stringParameterCheck(e,"DynamicsWebApi.update","key"),e=c.keyParameterCheck(e,"DynamicsWebApi.update","key"),c.parameterCheck(a,"DynamicsWebApi.update","object"),c.stringParameterCheck(t,"DynamicsWebApi.update","collection"),c.callbackParameterCheck(i,"DynamicsWebApi.update","successCallback"),c.callbackParameterCheck(r,"DynamicsWebApi.update","errorCallback"),n&&c.stringOrArrayParameterCheck(n,"DynamicsWebApi.update","prefer"),s&&c.arrayParameterCheck(s,"DynamicsWebApi.update","select");var o={collection:t,key:e,select:s,prefer:n,entity:a};this.updateRequest(o,i,r)},this.updateSingleProperty=function(e,t,i,r,n,s,o){c.stringParameterCheck(e,"DynamicsWebApi.updateSingleProperty","key"),e=c.keyParameterCheck(e,"DynamicsWebApi.updateSingleProperty","key"),c.parameterCheck(i,"DynamicsWebApi.updateSingleProperty","keyValuePair"),c.stringParameterCheck(t,"DynamicsWebApi.updateSingleProperty","collection"),c.callbackParameterCheck(r,"DynamicsWebApi.updateSingleProperty","successCallback"),c.callbackParameterCheck(n,"DynamicsWebApi.updateSingleProperty","errorCallback"),s&&c.stringOrArrayParameterCheck(s,"DynamicsWebApi.updateSingleProperty","prefer"),o&&c.arrayParameterCheck(o,"DynamicsWebApi.updateSingleProperty","select");var l=Object.keys(i)[0];a("PUT",{collection:t,key:e,select:o,prefer:s,navigationProperty:l,data:{value:i[l]}},"updateSingleProperty",function(e){e.data?r(e.data):r()},n)},this.deleteRequest=function(e,t,i){c.parameterCheck(e,"DynamicsWebApi.delete","request"),c.callbackParameterCheck(t,"DynamicsWebApi.delete","successCallback"),c.callbackParameterCheck(i,"DynamicsWebApi.delete","errorCallback");var r=function(){t(!0)},n=e.ifmatch;a("DELETE",e,"delete",r,function(e){n&&412==e.status?t(!1):i(e)})},this.deleteRecord=function(e,t,i,r,n){c.stringParameterCheck(e,"DynamicsWebApi.delete","key"),e=c.keyParameterCheck(e,"DynamicsWebApi.delete","key"),c.stringParameterCheck(t,"DynamicsWebApi.delete","collection"),c.callbackParameterCheck(i,"DynamicsWebApi.delete","successCallback"),c.callbackParameterCheck(r,"DynamicsWebApi.delete","errorCallback"),null!=n&&c.stringParameterCheck(n,"DynamicsWebApi.delete","propertyName"),a("DELETE",{key:e,collection:t,navigationProperty:n},"delete",function(e){i()},r)},this.retrieveRequest=function(e,t,i){c.parameterCheck(e,"DynamicsWebApi.retrieve","request"),c.callbackParameterCheck(t,"DynamicsWebApi.retrieve","successCallback"),c.callbackParameterCheck(i,"DynamicsWebApi.retrieve","errorCallback");var r=e.select;a("GET",e,"retrieve",function(e){t(null!=r&&1==r.length&&r[0].endsWith("/$ref")&&null!=e.data["@odata.id"]?n.convertToReferenceObject(e.data):e.data)},i)},this.retrieve=function(e,t,a,i,r,n){c.stringParameterCheck(e,"DynamicsWebApi.retrieve","key"),e=c.keyParameterCheck(e,"DynamicsWebApi.retrieve","key"),c.stringParameterCheck(t,"DynamicsWebApi.retrieve","collection"),c.callbackParameterCheck(a,"DynamicsWebApi.retrieve","successCallback"),c.callbackParameterCheck(i,"DynamicsWebApi.retrieve","errorCallback"),r&&r.length&&c.arrayParameterCheck(r,"DynamicsWebApi.retrieve","select"),n&&n.length&&c.stringOrArrayParameterCheck(n,"DynamicsWebApi.retrieve","expand");var s={collection:t,key:e,select:r,expand:n};this.retrieveRequest(s,a,i)},this.upsertRequest=function(e,t,i){c.parameterCheck(e,"DynamicsWebApi.upsert","request"),c.parameterCheck(e.entity,"DynamicsWebApi.upsert","request.entity"),c.callbackParameterCheck(t,"DynamicsWebApi.upsert","successCallback"),c.callbackParameterCheck(i,"DynamicsWebApi.upsert","errorCallback");var r=e.ifnonematch,n=e.ifmatch;a("PATCH",e,"upsert",function(e){if(e.headers["OData-EntityId"]||e.headers["odata-entityid"]){var a=e.headers["OData-EntityId"]?e.headers["OData-EntityId"]:e.headers["odata-entityid"];t(/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(a)[0])}else e.data?t(e.data):t()},function(e){r&&412==e.status?t():n&&404==e.status?t():i(e)})},this.upsert=function(e,t,a,i,r,n,s){c.stringParameterCheck(e,"DynamicsWebApi.upsert","key"),e=c.keyParameterCheck(e,"DynamicsWebApi.upsert","key"),c.parameterCheck(a,"DynamicsWebApi.upsert","object"),c.stringParameterCheck(t,"DynamicsWebApi.upsert","collection"),c.callbackParameterCheck(i,"DynamicsWebApi.upsert","successCallback"),c.callbackParameterCheck(r,"DynamicsWebApi.upsert","errorCallback"),n&&c.stringOrArrayParameterCheck(n,"DynamicsWebApi.upsert","prefer"),s&&c.arrayParameterCheck(s,"DynamicsWebApi.upsert","select");var o={collection:t,key:e,select:s,prefer:n,entity:a};this.upsertRequest(o,i,r)},this.count=function(e,t,i,r){if(null!=r&&(null==r||r.length))return this.retrieveMultipleRequest({collection:e,filter:r,count:!0},function(e){t(e.oDataCount?e.oDataCount:0)},i);c.stringParameterCheck(e,"DynamicsWebApi.count","collection"),c.callbackParameterCheck(t,"DynamicsWebApi.count","successCallback"),c.callbackParameterCheck(i,"DynamicsWebApi.count","errorCallback"),a("GET",{collection:e,navigationProperty:"$count"},"count",function(e){t(e.data?parseInt(e.data):0)},i)},this.countAll=function(e,t,a,i,r){return this.retrieveAllRequest({collection:e,filter:i,select:r},function(e){t(e&&e.value?e.value.length:0)},a)},this.retrieveMultiple=function(e,t,a,i,r,n){return this.retrieveMultipleRequest({collection:e,select:i,filter:r},t,a,n)},this.retrieveAll=function(e,t,a,i,r){return l({collection:e,select:i,filter:r},t,a)};var o=function(e,t,i,r){c.callbackParameterCheck(t,"DynamicsWebApi.retrieveMultiple","successCallback"),c.callbackParameterCheck(i,"DynamicsWebApi.retrieveMultiple","errorCallback"),r&&(c.stringParameterCheck(r,"DynamicsWebApi.retrieveMultiple","nextPageLink"),e.url=r);var n=e.count;a("GET",e,"retrieveMultiple",function(e){n&&(e.data.oDataCount=e.data.oDataCount||0),t(e.data)},i)};this.retrieveMultipleRequest=o;var l=function(e,t,a,i,r){var r=r||[];o(e,function(i){r=r.concat(i.value),i.oDataNextLink?l(e,t,a,i.oDataNextLink,r):t({value:r})},a,i)};this.retrieveAllRequest=function(e,t,a){l(e,t,a)};var u=function(e,t,i,s,o,l,u,p){c.stringParameterCheck(e,"DynamicsWebApi.executeFetchXml","collection"),c.stringParameterCheck(t,"DynamicsWebApi.executeFetchXml","fetchXml"),c.callbackParameterCheck(i,"DynamicsWebApi.executeFetchXml","successCallback"),c.callbackParameterCheck(s,"DynamicsWebApi.executeFetchXml","errorCallback"),l=l||1,c.numberParameterCheck(l,"DynamicsWebApi.executeFetchXml","pageNumber");var m='$1 page="'+l+'"';null!=u&&(c.stringParameterCheck(u,"DynamicsWebApi.executeFetchXml","pagingCookie"),m+=' paging-cookie="'+u+'"'),t=t.replace(/^(a.length)&&(t=a.length),t-=e.length;var i=a.lastIndexOf(e,t);return i!==-1&&i===t},String.prototype.startsWith=function(e,t){return t=t||0,this.substr(t,e.length)===e}},function(e,t,a){function i(e,t,a,n,o){var s={},l=[];if(n=null!=n?n:"&",e){if(e.navigationProperty){if(r.stringParameterCheck(e.navigationProperty,"DynamicsWebApi."+t,"request.navigationProperty"),a+="/"+e.navigationProperty,e.navigationPropertyKey){a+="("+r.keyParameterCheck(e.navigationPropertyKey,"DynamicsWebApi."+t,"request.navigationPropertyKey")+")"}"Attributes"===e.navigationProperty&&e.metadataAttributeType&&(r.stringParameterCheck(e.metadataAttributeType,"DynamicsWebApi."+t,"request.metadataAttributeType"),a+="/"+e.metadataAttributeType)}if(null!=e.select&&e.select.length&&(r.arrayParameterCheck(e.select,"DynamicsWebApi."+t,"request.select"),"retrieve"==t&&1==e.select.length&&e.select[0].endsWith("/$ref")?a+="/"+e.select[0]:(e.select[0].startsWith("/")&&"retrieve"==t&&(null==e.navigationProperty?a+=e.select.shift():e.select.shift()),e.select.length&&l.push("$select="+e.select.join(",")))),e.filter){r.stringParameterCheck(e.filter,"DynamicsWebApi."+t,"request.filter");for(var u=/[^"']{([\w\d]{8}[-]?(?:[\w\d]{4}[-]?){3}[\w\d]{12})}(?:[^"']|$)/g,p=e.filter;null!==(m=u.exec(p));){m.index===u.lastIndex&®ex.lastIndex++;var y=m[0].endsWith(")")?")":" ";p=p.replace(m[0]," "+m[1]+y)}l.push("$filter="+encodeURIComponent(p))}e.savedQuery&&l.push("savedQuery="+r.guidParameterCheck(e.savedQuery,"DynamicsWebApi."+t,"request.savedQuery")),e.userQuery&&l.push("userQuery="+r.guidParameterCheck(e.userQuery,"DynamicsWebApi."+t,"request.userQuery")),e.count&&(r.boolParameterCheck(e.count,"DynamicsWebApi."+t,"request.count"),l.push("$count="+e.count)),e.top&&e.top>0&&(r.numberParameterCheck(e.top,"DynamicsWebApi."+t,"request.top"),l.push("$top="+e.top)),null!=e.orderBy&&e.orderBy.length&&(r.arrayParameterCheck(e.orderBy,"DynamicsWebApi."+t,"request.orderBy"),l.push("$orderby="+e.orderBy.join(",")));var h=c(e,t,o);if(h.length&&(s.Prefer=h),null!=e.ifmatch&&null!=e.ifnonematch)throw new Error("DynamicsWebApi."+t+". Either one of request.ifmatch or request.ifnonematch parameters should be used in a call, not both.");if(e.ifmatch&&(r.stringParameterCheck(e.ifmatch,"DynamicsWebApi."+t,"request.ifmatch"),s["If-Match"]=e.ifmatch),e.ifnonematch&&(r.stringParameterCheck(e.ifnonematch,"DynamicsWebApi."+t,"request.ifnonematch"),s["If-None-Match"]=e.ifnonematch),e.impersonate&&(r.stringParameterCheck(e.impersonate,"DynamicsWebApi."+t,"request.impersonate"),s.MSCRMCallerID=r.guidParameterCheck(e.impersonate,"DynamicsWebApi."+t,"request.impersonate")),e.token&&(r.stringParameterCheck(e.token,"DynamicsWebApi."+t,"request.token"),s.Authorization="Bearer "+e.token),e.duplicateDetection&&(r.boolParameterCheck(e.duplicateDetection,"DynamicsWebApi."+t,"request.duplicateDetection"),s["MSCRM.SuppressDuplicateDetection"]="false"),e.entity&&r.parameterCheck(e.entity,"DynamicsWebApi."+t,"request.entity"),e.data&&r.parameterCheck(e.data,"DynamicsWebApi."+t,"request.data"),e.noCache&&(r.boolParameterCheck(e.noCache,"DynamicsWebApi."+t,"request.noCache"),s["Cache-Control"]="no-cache"),e.mergeLabels&&(r.boolParameterCheck(e.mergeLabels,"DynamicsWebApi."+t,"request.mergeLabels"),s["MSCRM.MergeLabels"]="true"),e.expand&&e.expand.length)if(r.stringOrArrayParameterCheck(e.expand,"DynamicsWebApi."+t,"request.expand"),"string"==typeof e.expand)l.push("$expand="+e.expand);else{for(var f=[],b=0;b2){var c=i(r[1]);m.isNull(c)||(a=a.replace(n,c+"$2"))}}a.startsWith(t.webApiUrl)||(a=t.webApiUrl+a.replace(/^\\/,""))}}else(e.startsWith("oData")||e.endsWith("_Formatted")||e.endsWith("_NavigationProperty")||e.endsWith("_LogicalName"))&&(a=void 0);return a}),a=a.replace(/[\u007F-\uFFFF]/g,function(e){return"\\u"+("0000"+e.charCodeAt(0).toString(16)).substr(-4)})),a}function c(e,t,i,c,o,s,l,u){o||(o={}),o=n(o);var p=r(c,i);if(t.length>2e3){var y="dwa_batch_"+m.generateUUID(),h=[];h.push("--"+y),h.push("Content-Type: application/http"),h.push("Content-Transfer-Encoding: binary\n"),h.push(e+" "+i.webApiUrl+t+" HTTP/1.1");for(var f in o)h.push(f+": "+o[f]),"Authorization"!=f&&delete o[f];h.push("\n--"+y+"--"),p=h.join("\n"),o=n(o),o["Content-Type"]="multipart/mixed;boundary="+y,t="$batch",e="POST"}i.impersonate&&!o.MSCRMCallerID&&(o.MSCRMCallerID=i.impersonate);var b;b=a(9);var d=function(a){a&&(o||(o={}),o.Authorization="Bearer "+(a.hasOwnProperty("accessToken")?a.accessToken:a)),b(e,i.webApiUrl+t,p,o,s,l,u)};i.onTokenRefresh&&(!o||o&&!o.Authorization)?i.onTokenRefresh(d):d()}function o(e,t,a,n){var r=function(t){p={};for(var n=0;n-1}function l(e,t,a,n){if(s(e)||m.isNull(e))return void a(e);if(e=e.toLowerCase(),!t.useEntityNames)return void a(e);try{var r=i(e);m.isNull(r)?o(e,t,a,n):a(r)}catch(e){n({message:"Unable to fetch Collection Names. Error: "+e.message})}}function u(e,t,a,i,n,r){var o=function(o){t.collection=o;var s=y.convertRequest(t,a,i);c(e,s.url,i,t.data||t.entity,s.headers,n,r,s.async)};l(t.collection,i,o,r)}var p,m=(a(0),a(4)),y=a(3);e.exports={sendRequest:c,makeRequest:u,getCollectionName:i}},function(e,t){e.exports=function(e,t){var a;return"string"==typeof t&&(a=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:Z|[-+]\d{2}:\d{2})$/.exec(t))?new Date(Date.UTC(+a[1],+a[2]-1,+a[3],+a[4],+a[5],+a[6])):t}},function(e,t,a){function i(e){var t=e.substr(0,e.indexOf("\r\n")),a=e.split(t);a.shift(),a.pop();for(var i=[],n=0;n-1?i(e)[0]:JSON.parse(e,o),t=r(t)),t}},function(e,t){e.exports=function(e){var t={};if(!e)return t;for(var a=e.split("\r\n"),i=0,n=a.length;i0&&(t[r.substring(0,c)]=r.substring(c+2))}return t}},function(e,t,a){var i=a(7),n=a(8),r=function(e,t,a,r,c,o,s){var l=new XMLHttpRequest;l.open(e,t,s);for(var u in r)l.setRequestHeader(u,r[u]);l.onreadystatechange=function(){if(4===l.readyState){switch(l.status){case 200:case 201:case 204:case 304:c({data:i(l.responseText),headers:n(l.getAllResponseHeaders()),status:l.status});break;default:var e;try{e=JSON.parse(l.response).error}catch(t){e=l.response.length>0?{message:l.response}:{message:"Unexpected Error"}}e.status=l.status,e.statusText=l.statusText,o(e)}l=null}},l.onerror=function(){o({message:"Network Error"}),l=null},l.ontimeout=function(e){o({message:"Request Timed Out"}),l=null},a?l.send(a):l.send()};e.exports=r},function(e,t){e.exports=function(e){if(e){for(var t=Object.keys(e),a="",i="",n=1;n<=t.length;n++){var r=t[n-1],c=e[r];n>1&&(a+=",",i+="&"),a+=r+"=@p"+n,i+="@p"+n+"="+("string"==typeof c?"'"+c+"'":c)}return"("+a+")?"+i}return"()"}},function(e,t,a){var i=a(0),n=a(1);e.exports=function(e,t,a){var r,c=e.returnRepresentation,o=e.includeAnnotations,s=e.maxPageSize;if(e.prefer&&e.prefer.length){n.stringOrArrayParameterCheck(e.prefer,"DynamicsWebApi."+t,"request.prefer"),r=e.prefer,"string"==typeof r&&(r=r.split(","));for(var l in r){var u=r[l].trim();u===i.Prefer.ReturnRepresentation?c=!0:u.startsWith("odata.include-annotations=")?o=u.replace("odata.include-annotations=","").replace(/"/g,""):u.startsWith("odata.maxpagesize=")&&(s=u.replace("odata.maxpagesize=","").replace(/"/g,""))}}return r=[],a&&(null==c&&(c=a.returnRepresentation),o=o?o:a.includeAnnotations,s=s?s:a.maxPageSize),c&&(n.boolParameterCheck(c,"DynamicsWebApi."+t,"request.returnRepresentation"),r.push(i.Prefer.ReturnRepresentation)),o&&(n.stringParameterCheck(o,"DynamicsWebApi."+t,"request.includeAnnotations"),r.push('odata.include-annotations="'+o+'"')),s&&s>0&&(n.numberParameterCheck(s,"DynamicsWebApi."+t,"request.maxPageSize"),r.push("odata.maxpagesize="+s)),r.join(",")}},function(e,t){e.exports=function(e){var t=/\/(\w+)\(([0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12})/i.exec(e["@odata.id"]);return{id:t[2],collection:t[1],oDataContext:e["@odata.context"]}}},function(e,t){e.exports=function(e,t){e=e?e:"",t=t?t:1,e=unescape(unescape(e));var a=/pagingcookie="()/.exec(e);if(null!=a){var i=parseInt(a[2]);return{cookie:a[1].replace(//g,">").replace(/\"/g,"'").replace(/\'/g,"""),page:i,nextPage:i+1}}return{cookie:"",page:t,nextPage:t+1}}},function(e,t,a){function i(e){var t={webApiVersion:"8.0",webApiUrl:"",impersonate:null,onTokenRefresh:null,includeAnnotations:null,maxPageSize:null,returnRepresentation:null};e||(e=t),this.setConfig=function(e){e.webApiVersion&&(c.stringParameterCheck(e.webApiVersion,"DynamicsWebApi.setConfig","config.webApiVersion"),t.webApiVersion=e.webApiVersion),e.webApiUrl?(c.stringParameterCheck(e.webApiUrl,"DynamicsWebApi.setConfig","config.webApiUrl"),t.webApiUrl=e.webApiUrl):t.webApiUrl=r.initWebApiUrl(t.webApiVersion),e.impersonate&&(t.impersonate=c.guidParameterCheck(e.impersonate,"DynamicsWebApi.setConfig","config.impersonate")),e.onTokenRefresh&&(c.callbackParameterCheck(e.onTokenRefresh,"DynamicsWebApi.setConfig","config.onTokenRefresh"),t.onTokenRefresh=e.onTokenRefresh),e.includeAnnotations&&(c.stringParameterCheck(e.includeAnnotations,"DynamicsWebApi.setConfig","config.includeAnnotations"),t.includeAnnotations=e.includeAnnotations),e.maxPageSize&&(c.numberParameterCheck(e.maxPageSize,"DynamicsWebApi.setConfig","config.maxPageSize"),t.maxPageSize=e.maxPageSize),e.returnRepresentation&&(c.boolParameterCheck(e.returnRepresentation,"DynamicsWebApi.setConfig","config.returnRepresentation"),t.returnRepresentation=e.returnRepresentation),e.useEntityNames&&(c.boolParameterCheck(e.useEntityNames,"DynamicsWebApi.setConfig","config.useEntityNames"),t.useEntityNames=e.useEntityNames)},this.setConfig(e);var a=function(e,a,i,n,r){o.makeRequest(e,a,i,t,n,r)};this.createRequest=function(e,t,i){c.parameterCheck(e,"DynamicsWebApi.create","request"),c.callbackParameterCheck(t,"DynamicsWebApi.create","successCallback"),c.callbackParameterCheck(i,"DynamicsWebApi.create","errorCallback"),a("POST",e,"create",function(e){if(e.data)t(e.data);else{var a=e.headers["OData-EntityId"]?e.headers["OData-EntityId"]:e.headers["odata-entityid"];t(/([0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12})\)$/i.exec(a)[1])}},i)},this.create=function(e,t,a,i,n,r){c.parameterCheck(e,"DynamicsWebApi.create","object"),c.stringParameterCheck(t,"DynamicsWebApi.create","collection"),n&&c.stringOrArrayParameterCheck(n,"DynamicsWebApi.create","prefer"),r&&c.arrayParameterCheck(r,"DynamicsWebApi.create","select");var o={collection:t,select:r,prefer:n,entity:e};this.createRequest(o,a,i)},this.updateRequest=function(e,t,i){c.parameterCheck(e,"DynamicsWebApi.update","request"),c.callbackParameterCheck(t,"DynamicsWebApi.update","successCallback"),c.callbackParameterCheck(i,"DynamicsWebApi.update","errorCallback"),null==e.ifmatch&&(e.ifmatch="*");var n=function(e){t(e.data?e.data:!0)},r=e.ifmatch,o=function(e){r&&412===e.status?t(!1):i(e)};a(/EntityDefinitions|RelationshipDefinitions|GlobalOptionSetDefinitions/.test(e.collection)?"PUT":"PATCH",e,"update",n,o)},this.update=function(e,t,a,i,n,r,o){c.stringParameterCheck(e,"DynamicsWebApi.update","key"),e=c.keyParameterCheck(e,"DynamicsWebApi.update","key"),c.parameterCheck(a,"DynamicsWebApi.update","object"),c.stringParameterCheck(t,"DynamicsWebApi.update","collection"),c.callbackParameterCheck(i,"DynamicsWebApi.update","successCallback"),c.callbackParameterCheck(n,"DynamicsWebApi.update","errorCallback"),r&&c.stringOrArrayParameterCheck(r,"DynamicsWebApi.update","prefer"),o&&c.arrayParameterCheck(o,"DynamicsWebApi.update","select");var s={collection:t,key:e,select:o,prefer:r,entity:a};this.updateRequest(s,i,n)},this.updateSingleProperty=function(e,t,i,n,r,o,s){c.stringParameterCheck(e,"DynamicsWebApi.updateSingleProperty","key"),e=c.keyParameterCheck(e,"DynamicsWebApi.updateSingleProperty","key"),c.parameterCheck(i,"DynamicsWebApi.updateSingleProperty","keyValuePair"),c.stringParameterCheck(t,"DynamicsWebApi.updateSingleProperty","collection"),c.callbackParameterCheck(n,"DynamicsWebApi.updateSingleProperty","successCallback"),c.callbackParameterCheck(r,"DynamicsWebApi.updateSingleProperty","errorCallback"),o&&c.stringOrArrayParameterCheck(o,"DynamicsWebApi.updateSingleProperty","prefer"),s&&c.arrayParameterCheck(s,"DynamicsWebApi.updateSingleProperty","select");var l=Object.keys(i)[0];a("PUT",{collection:t,key:e,select:s,prefer:o,navigationProperty:l,data:{value:i[l]}},"updateSingleProperty",function(e){e.data?n(e.data):n()},r)},this.deleteRequest=function(e,t,i){c.parameterCheck(e,"DynamicsWebApi.delete","request"),c.callbackParameterCheck(t,"DynamicsWebApi.delete","successCallback"),c.callbackParameterCheck(i,"DynamicsWebApi.delete","errorCallback");var n=function(){t(!0)},r=e.ifmatch;a("DELETE",e,"delete",n,function(e){r&&412===e.status?t(!1):i(e)})},this.deleteRecord=function(e,t,i,n,r){c.stringParameterCheck(e,"DynamicsWebApi.delete","key"),e=c.keyParameterCheck(e,"DynamicsWebApi.delete","key"),c.stringParameterCheck(t,"DynamicsWebApi.delete","collection"),c.callbackParameterCheck(i,"DynamicsWebApi.delete","successCallback"),c.callbackParameterCheck(n,"DynamicsWebApi.delete","errorCallback"),null!=r&&c.stringParameterCheck(r,"DynamicsWebApi.delete","propertyName"),a("DELETE",{key:e,collection:t,navigationProperty:r},"delete",function(e){i()},n)},this.retrieveRequest=function(e,t,i){c.parameterCheck(e,"DynamicsWebApi.retrieve","request"),c.callbackParameterCheck(t,"DynamicsWebApi.retrieve","successCallback"),c.callbackParameterCheck(i,"DynamicsWebApi.retrieve","errorCallback");var n=e.select;a("GET",e,"retrieve",function(e){t(null!=n&&1===n.length&&n[0].endsWith("/$ref")&&null!=e.data["@odata.id"]?r.convertToReferenceObject(e.data):e.data)},i)},this.retrieve=function(e,t,a,i,n,r){c.stringParameterCheck(e,"DynamicsWebApi.retrieve","key"),e=c.keyParameterCheck(e,"DynamicsWebApi.retrieve","key"),c.stringParameterCheck(t,"DynamicsWebApi.retrieve","collection"),c.callbackParameterCheck(a,"DynamicsWebApi.retrieve","successCallback"),c.callbackParameterCheck(i,"DynamicsWebApi.retrieve","errorCallback"),n&&n.length&&c.arrayParameterCheck(n,"DynamicsWebApi.retrieve","select"),r&&r.length&&c.stringOrArrayParameterCheck(r,"DynamicsWebApi.retrieve","expand");var o={collection:t,key:e,select:n,expand:r};this.retrieveRequest(o,a,i)},this.upsertRequest=function(e,t,i){c.parameterCheck(e,"DynamicsWebApi.upsert","request"),c.parameterCheck(e.entity,"DynamicsWebApi.upsert","request.entity"),c.callbackParameterCheck(t,"DynamicsWebApi.upsert","successCallback"),c.callbackParameterCheck(i,"DynamicsWebApi.upsert","errorCallback");var n=e.ifnonematch,r=e.ifmatch;a("PATCH",e,"upsert",function(e){if(e.headers["OData-EntityId"]||e.headers["odata-entityid"]){var a=e.headers["OData-EntityId"]?e.headers["OData-EntityId"]:e.headers["odata-entityid"];t(/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(a)[0])}else e.data?t(e.data):t()},function(e){n&&412===e.status?t():r&&404===e.status?t():i(e)})},this.upsert=function(e,t,a,i,n,r,o){c.stringParameterCheck(e,"DynamicsWebApi.upsert","key"),e=c.keyParameterCheck(e,"DynamicsWebApi.upsert","key"),c.parameterCheck(a,"DynamicsWebApi.upsert","object"),c.stringParameterCheck(t,"DynamicsWebApi.upsert","collection"),c.callbackParameterCheck(i,"DynamicsWebApi.upsert","successCallback"),c.callbackParameterCheck(n,"DynamicsWebApi.upsert","errorCallback"),r&&c.stringOrArrayParameterCheck(r,"DynamicsWebApi.upsert","prefer"),o&&c.arrayParameterCheck(o,"DynamicsWebApi.upsert","select");var s={collection:t,key:e,select:o,prefer:r,entity:a};this.upsertRequest(s,i,n)},this.count=function(e,t,i,n){if(null==n||null!=n&&!n.length){c.stringParameterCheck(e,"DynamicsWebApi.count","collection"),c.callbackParameterCheck(t,"DynamicsWebApi.count","successCallback"),c.callbackParameterCheck(i,"DynamicsWebApi.count","errorCallback");a("GET",{collection:e,navigationProperty:"$count"},"count",function(e){t(e.data?parseInt(e.data):0)},i)}else this.retrieveMultipleRequest({collection:e,filter:n,count:!0},function(e){t(e.oDataCount?e.oDataCount:0)},i)},this.countAll=function(e,t,a,i,n){this.retrieveAllRequest({collection:e,filter:i,select:n},function(e){t(e&&e.value?e.value.length:0)},a)},this.retrieveMultiple=function(e,t,a,i,n,r){this.retrieveMultipleRequest({collection:e,select:i,filter:n},t,a,r)},this.retrieveAll=function(e,t,a,i,n){l({collection:e,select:i,filter:n},t,a)};var s=function(e,t,i,n){c.callbackParameterCheck(t,"DynamicsWebApi.retrieveMultiple","successCallback"),c.callbackParameterCheck(i,"DynamicsWebApi.retrieveMultiple","errorCallback"),n&&(c.stringParameterCheck(n,"DynamicsWebApi.retrieveMultiple","nextPageLink"),e.url=n);var r=e.count;a("GET",e,"retrieveMultiple",function(e){r&&(e.data.oDataCount=e.data.oDataCount||0),t(e.data)},i)};this.retrieveMultipleRequest=s;var l=function(e,t,a,i,n){n=n||[],s(e,function(i){n=n.concat(i.value),i.oDataNextLink?l(e,t,a,i.oDataNextLink,n):t({value:n})},a,i)};this.retrieveAllRequest=function(e,t,a){l(e,t,a)};var u=function(e,t,i,o,s,l,u,p){c.stringParameterCheck(e,"DynamicsWebApi.executeFetchXml","collection"),c.stringParameterCheck(t,"DynamicsWebApi.executeFetchXml","fetchXml"),c.callbackParameterCheck(i,"DynamicsWebApi.executeFetchXml","successCallback"),c.callbackParameterCheck(o,"DynamicsWebApi.executeFetchXml","errorCallback"),l=l||1,c.numberParameterCheck(l,"DynamicsWebApi.executeFetchXml","pageNumber");var m='$1 page="'+l+'"';null!=u&&(c.stringParameterCheck(u,"DynamicsWebApi.executeFetchXml","pagingCookie"),m+=' paging-cookie="'+u+'"'),t=t.replace(/^( -1 || - request.collection.indexOf('RelationshipDefinitions') > -1 + //Metadata definitions, cannot be updated using "PATCH" method + var method = /EntityDefinitions|RelationshipDefinitions|GlobalOptionSetDefinitions/.test(request.collection) ? 'PUT' : 'PATCH'; //copy locally @@ -1740,7 +1741,7 @@ function DynamicsWebApi(config) { return true; //updated }).catch(function (error) { - if (ifmatch && error.status == 412) { + if (ifmatch && error.status === 412) { //precondition failed - not updated return false; } @@ -1757,12 +1758,12 @@ function DynamicsWebApi(config) { * @param {Object} object - A JavaScript object valid for update operations. * @param {string} [prefer] - If set to "return=representation" the function will return an updated object * @param {Array} [select] - An Array representing the $select Query Option to control which attributes will be returned. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.update = function (key, collection, object, prefer, select) { ErrorHelper.stringParameterCheck(key, "DynamicsWebApi.update", "key"); - key = ErrorHelper.keyParameterCheck(key, "DynamicsWebApi.update", "key") + key = ErrorHelper.keyParameterCheck(key, "DynamicsWebApi.update", "key"); ErrorHelper.parameterCheck(object, "DynamicsWebApi.update", "object"); ErrorHelper.stringParameterCheck(collection, "DynamicsWebApi.update", "collection"); @@ -1793,12 +1794,12 @@ function DynamicsWebApi(config) { * @param {Object} keyValuePair - keyValuePair object with a logical name of the field as a key and a value to update with. Example: {subject: "Update Record"} * @param {string|Array} [prefer] - If set to "return=representation" the function will return an updated object * @param {Array} [select] - An Array representing the $select Query Option to control which attributes will be returned. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.updateSingleProperty = function (key, collection, keyValuePair, prefer, select) { ErrorHelper.stringParameterCheck(key, "DynamicsWebApi.updateSingleProperty", "key"); - key = ErrorHelper.keyParameterCheck(key, "DynamicsWebApi.updateSingleProperty", "key") + key = ErrorHelper.keyParameterCheck(key, "DynamicsWebApi.updateSingleProperty", "key"); ErrorHelper.parameterCheck(keyValuePair, "DynamicsWebApi.updateSingleProperty", "keyValuePair"); ErrorHelper.stringParameterCheck(collection, "DynamicsWebApi.updateSingleProperty", "collection"); @@ -1834,18 +1835,18 @@ function DynamicsWebApi(config) { * Sends an asynchronous request to delete a record. * * @param {DWARequest} request - An object that represents all possible options for a current request. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.deleteRequest = function (request) { - ErrorHelper.parameterCheck(request, 'DynamicsWebApi.delete', 'request') + ErrorHelper.parameterCheck(request, 'DynamicsWebApi.delete', 'request'); //copy locally var ifmatch = request.ifmatch; return _makeRequest('DELETE', request, 'delete').then(function () { return true; //deleted }).catch(function (error) { - if (ifmatch && error.status == 412) { + if (ifmatch && error.status === 412) { //precondition failed - not deleted return false; } @@ -1854,7 +1855,7 @@ function DynamicsWebApi(config) { throw error; } }); - } + }; /** * Sends an asynchronous request to delete a record. @@ -1862,7 +1863,7 @@ function DynamicsWebApi(config) { * @param {string} key - A String representing the GUID value or Alternate Key for the record to delete. * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {string} [propertyName] - The name of the property which needs to be emptied. Instead of removing a whole record only the specified property will be cleared. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.deleteRecord = function (key, collection, propertyName) { ErrorHelper.stringParameterCheck(collection, 'DynamicsWebApi.deleteRecord', 'collection'); @@ -1878,17 +1879,17 @@ function DynamicsWebApi(config) { return _makeRequest('DELETE', request, 'deleteRecord').then(function () { return; - }) + }); }; /** * Sends an asynchronous request to upsert a record. * * @param {DWARequest} request - An object that represents all possible options for a current request. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.upsertRequest = function (request) { - ErrorHelper.parameterCheck(request, "DynamicsWebApi.upsert", "request") + ErrorHelper.parameterCheck(request, "DynamicsWebApi.upsert", "request"); //copy locally var ifnonematch = request.ifnonematch; @@ -1906,11 +1907,11 @@ function DynamicsWebApi(config) { return response.data; } }).catch(function (error) { - if (ifnonematch && error.status == 412) { + if (ifnonematch && error.status === 412) { //if prevent update return; } - else if (ifmatch && error.status == 404) { + else if (ifmatch && error.status === 404) { //if prevent create return; } @@ -1927,12 +1928,12 @@ function DynamicsWebApi(config) { * @param {Object} object - A JavaScript object valid for update operations. * @param {string|Array} [prefer] - If set to "return=representation" the function will return an updated object * @param {Array} [select] - An Array representing the $select Query Option to control which attributes will be returned. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.upsert = function (key, collection, object, prefer, select) { ErrorHelper.stringParameterCheck(key, "DynamicsWebApi.upsert", "key"); - key = ErrorHelper.keyParameterCheck(key, "DynamicsWebApi.upsert", "key") + key = ErrorHelper.keyParameterCheck(key, "DynamicsWebApi.upsert", "key"); ErrorHelper.parameterCheck(object, "DynamicsWebApi.upsert", "object"); ErrorHelper.stringParameterCheck(collection, "DynamicsWebApi.upsert", "collection"); @@ -1954,7 +1955,7 @@ function DynamicsWebApi(config) { }; return this.upsertRequest(request); - } + }; var retrieveMultipleRequest = function (request, nextPageLink) { @@ -1982,12 +1983,12 @@ function DynamicsWebApi(config) { * * @param {DWARequest} request - An object that represents all possible options for a current request. * @param {string} [nextPageLink] - Use the value of the @odata.nextLink property with a new GET request to return the next page of data. Pass null to retrieveMultipleOptions. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.retrieveMultipleRequest = retrieveMultipleRequest; var _retrieveAllRequest = function (request, nextPageLink, records) { - var records = records || []; + records = records || []; return retrieveMultipleRequest(request, nextPageLink).then(function (response) { records = records.concat(response.value); @@ -1998,13 +1999,13 @@ function DynamicsWebApi(config) { return { value: records }; }); - } + }; /** * Sends an asynchronous request to retrieve all records. * * @param {DWARequest} request - An object that represents all possible options for a current request. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.retrieveAllRequest = function (request) { return _retrieveAllRequest(request); @@ -2015,7 +2016,7 @@ function DynamicsWebApi(config) { * * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {string} [filter] - Use the $filter system query option to set criteria for which entities will be returned. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.count = function (collection, filter) { if (filter == null || (filter != null && !filter.length)) { @@ -2041,7 +2042,7 @@ function DynamicsWebApi(config) { return response.oDataCount ? response.oDataCount : 0; }); } - } + }; /** * Sends an asynchronous request to count records. Returns: Number @@ -2049,7 +2050,7 @@ function DynamicsWebApi(config) { * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {string} [filter] - Use the $filter system query option to set criteria for which entities will be returned. * @param {Array} [select] - An Array representing the $select Query Option to control which attributes will be returned. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.countAll = function (collection, filter, select) { return _retrieveAllRequest({ @@ -2062,7 +2063,7 @@ function DynamicsWebApi(config) { ? (response.value ? response.value.length : 0) : 0; }); - } + }; /** * Sends an asynchronous request to retrieve records. @@ -2071,7 +2072,7 @@ function DynamicsWebApi(config) { * @param {Array} [select] - Use the $select system query option to limit the properties returned. * @param {string} [filter] - Use the $filter system query option to set criteria for which entities will be returned. * @param {string} [nextPageLink] - Use the value of the @odata.nextLink property with a new GET request to return the next page of data. Pass null to retrieveMultipleOptions. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.retrieveMultiple = function (collection, select, filter, nextPageLink) { return this.retrieveMultipleRequest({ @@ -2079,7 +2080,7 @@ function DynamicsWebApi(config) { select: select, filter: filter }, nextPageLink); - } + }; /** * Sends an asynchronous request to retrieve all records. @@ -2087,7 +2088,7 @@ function DynamicsWebApi(config) { * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {Array} [select] - Use the $select system query option to limit the properties returned. * @param {string} [filter] - Use the $filter system query option to set criteria for which entities will be returned. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.retrieveAll = function (collection, select, filter) { return _retrieveAllRequest({ @@ -2095,7 +2096,7 @@ function DynamicsWebApi(config) { select: select, filter: filter }); - } + }; var executeFetchXml = function (collection, fetchXml, includeAnnotations, pageNumber, pagingCookie, impersonateUserId) { @@ -2118,9 +2119,7 @@ function DynamicsWebApi(config) { collection: collection, includeAnnotations: includeAnnotations, impersonate: impersonateUserId, - fetchXml: fetchXml, - impersonate: impersonateUserId, - includeAnnotations: includeAnnotations + fetchXml: fetchXml }; return _makeRequest("GET", request, 'executeFetchXml') @@ -2132,7 +2131,7 @@ function DynamicsWebApi(config) { return response.data; }); - } + }; /** * Sends an asynchronous request to execute FetchXml to retrieve records. Returns: DWA.Types.FetchXmlResponse @@ -2143,7 +2142,7 @@ function DynamicsWebApi(config) { * @param {number} [pageNumber] - Page number. * @param {string} [pagingCookie] - Paging cookie. For retrieving the first page, pagingCookie should be null. * @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.fetch = executeFetchXml; @@ -2156,12 +2155,12 @@ function DynamicsWebApi(config) { * @param {number} [pageNumber] - Page number. * @param {string} [pagingCookie] - Paging cookie. For retrieving the first page, pagingCookie should be null. * @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.executeFetchXml = executeFetchXml; var _executeFetchXmlAll = function (collection, fetchXml, includeAnnotations, pageNumber, pagingCookie, impersonateUserId, records) { - var records = records || []; + records = records || []; return executeFetchXml(collection, fetchXml, includeAnnotations, pageNumber, pagingCookie, impersonateUserId, records).then(function (response) { records = records.concat(response.value); @@ -2172,11 +2171,11 @@ function DynamicsWebApi(config) { return { value: records }; }); - } + }; var innerExecuteFetchXmlAll = function (collection, fetchXml, includeAnnotations, impersonateUserId) { return _executeFetchXmlAll(collection, fetchXml, includeAnnotations, null, null, impersonateUserId); - } + }; /** * Sends an asynchronous request to execute FetchXml to retrieve all records. @@ -2185,7 +2184,7 @@ function DynamicsWebApi(config) { * @param {string} fetchXml - FetchXML is a proprietary query language that provides capabilities to perform aggregation. * @param {string} [includeAnnotations] - Use this parameter to include annotations to a result. For example: * or Microsoft.Dynamics.CRM.fetchxmlpagingcookie * @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.fetchAll = innerExecuteFetchXmlAll; @@ -2196,7 +2195,7 @@ function DynamicsWebApi(config) { * @param {string} fetchXml - FetchXML is a proprietary query language that provides capabilities to perform aggregation. * @param {string} [includeAnnotations] - Use this parameter to include annotations to a result. For example: * or Microsoft.Dynamics.CRM.fetchxmlpagingcookie * @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.executeFetchXmlAll = innerExecuteFetchXmlAll; @@ -2209,7 +2208,7 @@ function DynamicsWebApi(config) { * @param {string} relatedCollection - Related name of the Entity Collection or Entity Logical name. * @param {string} relatedKey - Related entity record id. * @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.associate = function (collection, primaryKey, relationshipName, relatedCollection, relatedKey, impersonateUserId) { ErrorHelper.stringParameterCheck(relatedCollection, "DynamicsWebApi.associate", "relatedcollection"); @@ -2227,7 +2226,7 @@ function DynamicsWebApi(config) { return _makeRequest("POST", request, 'associate') .then(function () { }); - } + }; /** * Disassociate for a collection-valued navigation property. @@ -2237,7 +2236,7 @@ function DynamicsWebApi(config) { * @param {string} relationshipName - Relationship name. * @param {string} relatedKey - Related entity record id. * @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.disassociate = function (collection, primaryKey, relationshipName, relatedKey, impersonateUserId) { ErrorHelper.stringParameterCheck(relationshipName, "DynamicsWebApi.disassociate", "relationshipName"); @@ -2247,12 +2246,12 @@ function DynamicsWebApi(config) { _additionalUrl: relationshipName + '(' + relatedKey + ')/$ref', collection: collection, key: primaryKey, - impersonate: impersonateUserId, + impersonate: impersonateUserId }; return _makeRequest("DELETE", request, 'disassociate') .then(function () { }); - } + }; /** * Associate for a single-valued navigation property. (1:N) @@ -2261,9 +2260,9 @@ function DynamicsWebApi(config) { * @param {string} key - Entity record Id that contains an attribute. * @param {string} singleValuedNavigationPropertyName - Single-valued navigation property name (usually it's a Schema Name of the lookup attribute). * @param {string} relatedCollection - Related collection name that the lookup (attribute) points to. - * @param {string} relatedId - Related entity record id that needs to be associated. + * @param {string} relatedKey - Related entity record id that needs to be associated. * @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.associateSingleValued = function (collection, key, singleValuedNavigationPropertyName, relatedCollection, relatedKey, impersonateUserId) { @@ -2281,7 +2280,7 @@ function DynamicsWebApi(config) { return _makeRequest("PUT", request, 'associateSingleValued') .then(function () { }); - } + }; /** * Removes a reference to an entity for a single-valued navigation property. (1:N) @@ -2290,7 +2289,7 @@ function DynamicsWebApi(config) { * @param {string} key - Entity record Id that contains an attribute. * @param {string} singleValuedNavigationPropertyName - Single-valued navigation property name (usually it's a Schema Name of the lookup attribute). * @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.disassociateSingleValued = function (collection, key, singleValuedNavigationPropertyName, impersonateUserId) { @@ -2300,12 +2299,12 @@ function DynamicsWebApi(config) { _additionalUrl: singleValuedNavigationPropertyName + "/$ref", key: key, collection: collection, - impersonate: impersonateUserId, + impersonate: impersonateUserId }; return _makeRequest("DELETE", request, 'disassociateSingleValued') .then(function () { }); - } + }; /** * Executes an unbound function (not bound to a particular entity record) @@ -2313,11 +2312,11 @@ function DynamicsWebApi(config) { * @param {string} functionName - The name of the function. * @param {Object} [parameters] - Function's input parameters. Example: { param1: "test", param2: 3 }. * @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.executeUnboundFunction = function (functionName, parameters, impersonateUserId) { return _executeFunction(functionName, parameters, null, null, impersonateUserId, true); - } + }; /** * Executes a bound function @@ -2327,11 +2326,11 @@ function DynamicsWebApi(config) { * @param {string} functionName - The name of the function. * @param {Object} [parameters] - Function's input parameters. Example: { param1: "test", param2: 3 }. * @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.executeBoundFunction = function (id, collection, functionName, parameters, impersonateUserId) { return _executeFunction(functionName, parameters, collection, id, impersonateUserId); - } + }; var _executeFunction = function (functionName, parameters, collection, id, impersonateUserId, isUnbound) { @@ -2342,7 +2341,7 @@ function DynamicsWebApi(config) { _unboundRequest: isUnbound, key: id, collection: collection, - impersonate: impersonateUserId, + impersonate: impersonateUserId }; return _makeRequest("GET", request, 'executeFunction').then(function (response) { @@ -2350,7 +2349,7 @@ function DynamicsWebApi(config) { return response.data; } }); - } + }; /** * Executes an unbound Web API action (not bound to a particular entity record) @@ -2358,11 +2357,11 @@ function DynamicsWebApi(config) { * @param {string} actionName - The name of the Web API action. * @param {Object} [requestObject] - Action request body object. * @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.executeUnboundAction = function (actionName, requestObject, impersonateUserId) { return _executeAction(actionName, requestObject, null, null, impersonateUserId, true); - } + }; /** * Executes a bound Web API action (bound to a particular entity record) @@ -2372,11 +2371,11 @@ function DynamicsWebApi(config) { * @param {string} actionName - The name of the Web API action. * @param {Object} [requestObject] - Action request body object. * @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.executeBoundAction = function (id, collection, actionName, requestObject, impersonateUserId) { return _executeAction(actionName, requestObject, collection, id, impersonateUserId); - } + }; var _executeAction = function (actionName, requestObject, collection, id, impersonateUserId, isUnbound) { @@ -2402,7 +2401,7 @@ function DynamicsWebApi(config) { * Sends an asynchronous request to create an entity definition. * * @param {string} entityDefinition - Entity Definition. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.createEntity = function (entityDefinition) { @@ -2420,7 +2419,7 @@ function DynamicsWebApi(config) { * * @param {string} entityDefinition - Entity Definition. * @param {boolean} [mergeLabels] - Sets MSCRM.MergeLabels header that controls whether to overwrite the existing labels or merge your new label with any existing language labels. Default value is false. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.updateEntity = function (entityDefinition, mergeLabels) { @@ -2442,7 +2441,7 @@ function DynamicsWebApi(config) { * @param {string} entityKey - The Entity MetadataId or Alternate Key (such as LogicalName). * @param {Array} [select] - Use the $select system query option to limit the properties returned. * @param {string|Array} [expand] - A String or Array of Expand Objects representing the $expand Query Option value to control which related records need to be returned. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.retrieveEntity = function (entityKey, select, expand) { @@ -2463,7 +2462,7 @@ function DynamicsWebApi(config) { * * @param {Array} [select] - Use the $select system query option to limit the properties returned. * @param {string} [filter] - Use the $filter system query option to set criteria for which entity definitions will be returned. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.retrieveEntities = function (select, filter) { var request = { @@ -2480,7 +2479,7 @@ function DynamicsWebApi(config) { * * @param {string} entityKey - The Entity MetadataId or Alternate Key (such as LogicalName). * @param {Object} attributeDefinition - Object that describes the attribute. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.createAttribute = function (entityKey, attributeDefinition) { ErrorHelper.keyParameterCheck(entityKey, 'DynamicsWebApi.createAttribute', 'entityKey'); @@ -2503,7 +2502,7 @@ function DynamicsWebApi(config) { * @param {Object} attributeDefinition - Object that describes the attribute. * @param {string} [attributeType] - Use this parameter to cast the Attribute to a specific type. * @param {boolean} [mergeLabels] - Sets MSCRM.MergeLabels header that controls whether to overwrite the existing labels or merge your new label with any existing language labels. Default value is false. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.updateAttribute = function (entityKey, attributeDefinition, attributeType, mergeLabels) { ErrorHelper.keyParameterCheck(entityKey, 'DynamicsWebApi.updateAttribute', 'entityKey'); @@ -2535,7 +2534,7 @@ function DynamicsWebApi(config) { * @param {Array} [select] - Use the $select system query option to limit the properties returned. * @param {string} [filter] - Use the $filter system query option to set criteria for which attribute definitions will be returned. * @param {string|Array} [expand] - A String or Array of Expand Objects representing the $expand Query Option value to control which related records need to be returned. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.retrieveAttributes = function (entityKey, attributeType, select, filter, expand) { @@ -2566,7 +2565,7 @@ function DynamicsWebApi(config) { * @param {string} [attributeType] - Use this parameter to cast the Attribute to a specific type. * @param {Array} [select] - Use the $select system query option to limit the properties returned. * @param {string|Array} [expand] - A String or Array of Expand Objects representing the $expand Query Option value to control which related records need to be returned. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.retrieveAttribute = function (entityKey, attributeKey, attributeType, select, expand) { @@ -2594,7 +2593,7 @@ function DynamicsWebApi(config) { * Sends an asynchronous request to create a relationship definition. * * @param {string} relationshipDefinition - Relationship Definition. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.createRelationship = function (relationshipDefinition) { @@ -2611,9 +2610,9 @@ function DynamicsWebApi(config) { * Sends an asynchronous request to update a relationship definition. * * @param {string} relationshipDefinition - Relationship Definition. - * @param {string} [attributeType] - Use this parameter to cast the Relationship to a specific type. + * @param {string} [relationshipType] - Use this parameter to cast the Relationship to a specific type. * @param {boolean} [mergeLabels] - Sets MSCRM.MergeLabels header that controls whether to overwrite the existing labels or merge your new label with any existing language labels. Default value is false. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.updateRelationship = function (relationshipDefinition, relationshipType, mergeLabels) { @@ -2635,7 +2634,7 @@ function DynamicsWebApi(config) { * Sends an asynchronous request to delete a relationship definition. * * @param {string} metadataId - A String representing the GUID value. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.deleteRelationship = function (metadataId) { ErrorHelper.keyParameterCheck(metadataId, 'DynamicsWebApi.deleteRelationship', 'metadataId'); @@ -2654,7 +2653,7 @@ function DynamicsWebApi(config) { * @param {string} [relationshipType] - Use this parameter to cast a Relationship to a specific type: 1:M or M:M. * @param {Array} [select] - Use the $select system query option to limit the properties returned. * @param {string} [filter] - Use the $filter system query option to set criteria for which relationships will be returned. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.retrieveRelationships = function (relationshipType, select, filter) { @@ -2671,10 +2670,10 @@ function DynamicsWebApi(config) { /** * Sends an asynchronous request to retrieve a specific relationship definition. * - * @param {string} - String representing the Metadata Id GUID. + * @param {string} metadataId - String representing the Metadata Id GUID. * @param {string} [relationshipType] - Use this parameter to cast a Relationship to a specific type: 1:M or M:M. * @param {Array} [select] - Use the $select system query option to limit the properties returned. - * @returns {Promise} + * @returns {Promise} D365 Web Api result */ this.retrieveRelationship = function (metadataId, relationshipType, select) { @@ -2690,11 +2689,106 @@ function DynamicsWebApi(config) { return this.retrieveRequest(request); }; + /** + * Sends an asynchronous request to create a Global Option Set definition + * + * @param {string} globalOptionSetDefinition - Global Option Set Definition. + * @returns {Promise} D365 Web Api result + */ + this.createGlobalOptionSet = function (globalOptionSetDefinition) { + + ErrorHelper.parameterCheck(globalOptionSetDefinition, 'DynamicsWebApi.createGlobalOptionSet', 'globalOptionSetDefinition'); + + var request = { + collection: 'GlobalOptionSetDefinitions', + entity: globalOptionSetDefinition + }; + + return this.createRequest(request); + }; + + /** + * Sends an asynchronous request to update a Global Option Set. + * + * @param {string} globalOptionSetDefinition - Global Option Set Definition. + * @param {boolean} [mergeLabels] - Sets MSCRM.MergeLabels header that controls whether to overwrite the existing labels or merge your new label with any existing language labels. Default value is false. + * @returns {Promise} D365 Web Api result + */ + this.updateGlobalOptionSet = function (globalOptionSetDefinition, mergeLabels) { + + ErrorHelper.parameterCheck(globalOptionSetDefinition, 'DynamicsWebApi.updateGlobalOptionSet', 'globalOptionSetDefinition'); + ErrorHelper.guidParameterCheck(globalOptionSetDefinition.MetadataId, 'DynamicsWebApi.updateGlobalOptionSet', 'globalOptionSetDefinition.MetadataId'); + + var request = { + collection: 'GlobalOptionSetDefinitions', + mergeLabels: mergeLabels, + key: globalOptionSetDefinition.MetadataId, + entity: globalOptionSetDefinition + }; + return this.updateRequest(request); + }; + + /** + * Sends an asynchronous request to delete a Global Option Set. + * + * @param {string} globalOptionSetKey - A String representing the GUID value or Alternate Key (such as Name). + * @returns {Promise} D365 Web Api result + */ + this.deleteGlobalOptionSet = function (globalOptionSetKey) { + ErrorHelper.keyParameterCheck(globalOptionSetKey, 'DynamicsWebApi.deleteGlobalOptionSet', 'globalOptionSetKey'); + + var request = { + collection: 'GlobalOptionSetDefinitions', + key: globalOptionSetKey + }; + + return this.deleteRequest(request); + }; + + /** + * Sends an asynchronous request to retrieve Global Option Set definitions. + * + * @param {string} globalOptionSetKey - The Global Option Set MetadataID or Alternate Key (such as Name). + * @param {string} [castType] - Use this parameter to cast a Global Option Set to a specific type. + * @param {Array} [select] - Use the $select system query option to limit the properties returned + * @returns {Promise} D365 Web Api result + */ + this.retrieveGlobalOptionSet = function (globalOptionSetKey, castType, select) { + ErrorHelper.keyParameterCheck(globalOptionSetKey, 'DynamicsWebApi.retrieveGlobalOptionSet', 'globalOptionSetKey'); + + var request = { + collection: 'GlobalOptionSetDefinitions', + key: globalOptionSetKey, + navigationProperty: castType, + select: select + }; + + return this.retrieveRequest(request); + }; + + /** + * Sends an asynchronous request to retrieve Global Option Set definitions. + * + * @param {string} [castType] - Use this parameter to cast a Global Option Set to a specific type. + * @param {Array} [select] - Use the $select system query option to limit the properties returned + * @returns {Promise} D365 Web Api result + */ + this.retrieveGlobalOptionSets = function (castType, select) { + + var request = { + collection: 'GlobalOptionSetDefinitions', + navigationProperty: castType, + select: select + }; + + return this.retrieveMultipleRequest(request); + }; + /** * Creates a new instance of DynamicsWebApi * * @param {DWAConfig} [config] - configuration object. - * @returns {DynamicsWebApi} + * @returns {DynamicsWebApi} The new instance of a DynamicsWebApi */ this.initializeInstance = function (config) { if (!config) { @@ -2703,7 +2797,7 @@ function DynamicsWebApi(config) { return new DynamicsWebApi(config); }; -}; +} /** * DynamicsWebApi Utility helper class diff --git a/dist/dynamics-web-api.min.js b/dist/dynamics-web-api.min.js index 05eaab3..49bd116 100644 --- a/dist/dynamics-web-api.min.js +++ b/dist/dynamics-web-api.min.js @@ -1,2 +1,2 @@ -/*! dynamics-web-api v1.4.5 (c) 2018 Aleksandr Rogov */ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("DynamicsWebApi",[],t):"object"==typeof exports?exports.DynamicsWebApi=t():e.DynamicsWebApi=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=14)}([function(e,t){var n={Types:{ResponseBase:function(){this.oDataContext=""},Response:function(){n.Types.ResponseBase.call(this),this.value={}},ReferenceResponse:function(){n.Types.ResponseBase.call(this),this.id="",this.collection=""},MultipleResponse:function(){n.Types.ResponseBase.call(this),this.oDataNextLink="",this.oDataCount=0,this.value=[]},FetchXmlResponse:function(){n.Types.ResponseBase.call(this),this.value=[],this.PagingInfo={cookie:"",page:0,nextPage:1}}},Prefer:{ReturnRepresentation:"return=representation",Annotations:{AssociatedNavigationProperty:"Microsoft.Dynamics.CRM.associatednavigationproperty",LookupLogicalName:"Microsoft.Dynamics.CRM.lookuplogicalname",All:"*",FormattedValue:"OData.Community.Display.V1.FormattedValue",FetchXmlPagingCookie:"Microsoft.Dynamics.CRM.fetchxmlpagingcookie"}}};e.exports=n},function(e,t){function n(e,t,n){throw new Error(n?e+" requires the "+t+" parameter to be of type "+n:e+" requires the "+t+" parameter.")}var r={handleErrorResponse:function(e){throw new Error("Error: "+e.status+": "+e.message)},parameterCheck:function(e,t,r,i){void 0!==e&&null!==e&&""!=e||n(t,r,i)},stringParameterCheck:function(e,t,r){"string"!=typeof e&&n(t,r,"String")},arrayParameterCheck:function(e,t,r){e.constructor!==Array&&n(t,r,"Array")},stringOrArrayParameterCheck:function(e,t,r){e.constructor!==Array&&"string"!=typeof e&&n(t,r,"String or Array")},numberParameterCheck:function(e,t,r){if("number"!=typeof e){if("string"==typeof e&&e&&!isNaN(parseInt(e)))return;n(t,r,"Number")}},boolParameterCheck:function(e,t,r){"boolean"!=typeof e&&n(t,r,"Boolean")},guidParameterCheck:function(e,t,r){try{return/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(e)[0]}catch(e){n(t,r,"GUID String")}},keyParameterCheck:function(e,t,i){try{r.stringParameterCheck(e,t,i);var a=/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(e);if(a)return a[0];var o=e.split(",");if(o.length)for(var s=0;sn.length)&&(t=n.length),t-=e.length;var r=n.lastIndexOf(e,t);return r!==-1&&r===t},String.prototype.startsWith=function(e,t){return t=t||0,this.substr(t,e.length)===e}},function(e,t,n){function r(e){return void 0===e||"unknown"==typeof e||null==e}function i(){var e=(new Date).getTime();return"undefined"!=typeof performance&&"function"==typeof performance.now&&(e+=performance.now()),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"===t?n:3&n|8).toString(16)})}function a(){if("undefined"!=typeof GetGlobalContext)return GetGlobalContext();if("undefined"!=typeof Xrm){if(!r(Xrm.Utility)&&!r(Xrm.Utility.getGlobalContext))return Xrm.Utility.getGlobalContext();if(!r(Xrm.Page)&&!r(Xrm.Page.context))return Xrm.Page.context}throw new Error("Xrm Context is not available. In most cases, it can be resolved by adding a reference to a ClientGlobalContext.js.aspx. Please refer to MSDN documentation for more details.")}function o(){var e=a();if(e){var t=e.getClientUrl();return t.match(/\/$/)&&(t=t.substring(0,t.length-1)),t}return""}function s(e){return o()+"/api/data/v"+e+"/"}function c(){return"undefined"!=typeof Xrm?Xrm.Internal:null}var u={buildFunctionParameters:n(10),getFetchXmlPagingCookie:n(13),convertToReferenceObject:n(12),isNull:r,generateUUID:i,getXrmContext:a,getXrmInternal:c,getClientUrl:o,initWebApiUrl:s};e.exports=u},function(e,t,n){function r(e){var t=h.getXrmInternal();if(!h.isNull(t)){var n=t.getEntitySetName(e);return n||e}var n=null;if(!h.isNull(p)&&(n=p[e],h.isNull(n)))for(var r in p)if(p[r]==e)return e;return n}function i(e){return e.Accept="application/json",e["OData-MaxVersion"]="4.0",e["OData-Version"]="4.0",e["Content-Type"]="application/json; charset=utf-8",e}function a(e,t){var n;return e&&(n=JSON.stringify(e,function(e,n){if(e.endsWith("@odata.bind")||e.endsWith("@odata.id")){if("string"==typeof n){if(/\(\{[\w\d-]+\}\)/g.test(n)&&(n=n.replace(/(.+)\(\{([\w\d-]+)\}\)/g,"$1($2)")),t.useEntityNames){var i=/([\w_]+)(\([\d\w-]+\))$/,a=i.exec(n);if(a.length>2){var o=r(a[1]);h.isNull(o)||(n=n.replace(i,o+"$2"))}}n.startsWith(t.webApiUrl)||(n=t.webApiUrl+n.replace(/^\\/,""))}}else(e.startsWith("oData")||e.endsWith("_Formatted")||e.endsWith("_NavigationProperty")||e.endsWith("_LogicalName"))&&(n=void 0);return n}),n=n.replace(/[\u007F-\uFFFF]/g,function(e){return"\\u"+("0000"+e.charCodeAt(0).toString(16)).substr(-4)})),n}function o(e,t,r,o,s,c,u,l){s||(s={}),s=i(s);var p=a(o,r);if(t.length>2e3){var m="dwa_batch_"+h.generateUUID(),f=[];f.push("--"+m),f.push("Content-Type: application/http"),f.push("Content-Transfer-Encoding: binary\n"),f.push(e+" "+r.webApiUrl+t+" HTTP/1.1");for(var y in s)f.push(y+": "+s[y]),"Authorization"!=y&&delete s[y];f.push("\n--"+m+"--"),p=f.join("\n"),s=i(s),s["Content-Type"]="multipart/mixed;boundary="+m,t="$batch",e="POST"}r.impersonate&&!s.MSCRMCallerID&&(s.MSCRMCallerID=r.impersonate);var d;d=n(8);var g=function(n){n&&(s||(s={}),s.Authorization="Bearer "+(n.hasOwnProperty("accessToken")?n.accessToken:n)),d(e,r.webApiUrl+t,p,s,c,u,l)};r.onTokenRefresh&&(!s||s&&!s.Authorization)?r.onTokenRefresh(g):g()}function s(e,t,n,i){var a=function(t){p={};for(var i=0;i-1}function u(e,t,n,i){if(c(e)||h.isNull(e))return void n(e);if(e=e.toLowerCase(),!t.useEntityNames)return void n(e);try{var a=r(e);h.isNull(a)?s(e,t,n,i):n(a)}catch(e){i({message:"Unable to fetch Collection Names. Error: "+e.message})}}function l(e,t,n,r,i,a){var s=function(s){t.collection=s;var c=m.convertRequest(t,n,r);o(e,c.url,r,t.data||t.entity,c.headers,i,a,c.async)};u(t.collection,r,s,a)}var p,h=(n(0),n(3)),m=n(9);e.exports={sendRequest:o,makeRequest:l,getCollectionName:r}},function(e,t){e.exports=function(e,t){var n;return"string"==typeof t&&(n=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:Z|[-+]\d{2}:\d{2})$/.exec(t))?new Date(Date.UTC(+n[1],+n[2]-1,+n[3],+n[4],+n[5],+n[6])):t}},function(e,t,n){function r(e){var t=e.substr(0,e.indexOf("\r\n")),n=e.split(t);n.shift(),n.pop();for(var r=[],i=0;i-1?r(e)[0]:JSON.parse(e,s),t=a(t)),t}},function(e,t){e.exports=function(e){var t={};if(!e)return t;for(var n=e.split("\r\n"),r=0,i=n.length;r0&&(t[a.substring(0,o)]=a.substring(o+2))}return t}},function(e,t,n){var r=n(6),i=n(7),a=function(e,t,n,a,o,s,c){var u=new XMLHttpRequest;u.open(e,t,c);for(var l in a)u.setRequestHeader(l,a[l]);u.onreadystatechange=function(){if(4===u.readyState){switch(u.status){case 200:case 201:case 204:case 304:o({data:r(u.responseText),headers:i(u.getAllResponseHeaders()),status:u.status});break;default:var e;try{e=JSON.parse(u.response).error}catch(t){e=u.response.length>0?{message:u.response}:{message:"Unexpected Error"}}e.status=u.status,e.statusText=u.statusText,s(e)}u=null}},u.onerror=function(){s({message:"Network Error"}),u=null},u.ontimeout=function(e){s({message:"Request Timed Out"}),u=null},n?u.send(n):u.send()};e.exports=a},function(e,t,n){function r(e,t,n,i,s){var c={},u=[];if(i=null!=i?i:"&",e){if(e.navigationProperty){if(a.stringParameterCheck(e.navigationProperty,"DynamicsWebApi."+t,"request.navigationProperty"),n+="/"+e.navigationProperty,e.navigationPropertyKey){n+="("+a.keyParameterCheck(e.navigationPropertyKey,"DynamicsWebApi."+t,"request.navigationPropertyKey")+")"}"Attributes"===e.navigationProperty&&e.metadataAttributeType&&(a.stringParameterCheck(e.metadataAttributeType,"DynamicsWebApi."+t,"request.metadataAttributeType"),n+="/"+e.metadataAttributeType)}if(null!=e.select&&e.select.length&&(a.arrayParameterCheck(e.select,"DynamicsWebApi."+t,"request.select"),"retrieve"==t&&1==e.select.length&&e.select[0].endsWith("/$ref")?n+="/"+e.select[0]:(e.select[0].startsWith("/")&&"retrieve"==t&&(null==e.navigationProperty?n+=e.select.shift():e.select.shift()),e.select.length&&u.push("$select="+e.select.join(",")))),e.filter){a.stringParameterCheck(e.filter,"DynamicsWebApi."+t,"request.filter");for(var l=/[^"']{([\w\d]{8}[-]?(?:[\w\d]{4}[-]?){3}[\w\d]{12})}(?:[^"']|$)/g,p=e.filter;null!==(m=l.exec(p));){m.index===l.lastIndex&®ex.lastIndex++;var h=m[0].endsWith(")")?")":" ";p=p.replace(m[0]," "+m[1]+h)}u.push("$filter="+encodeURIComponent(p))}e.savedQuery&&u.push("savedQuery="+a.guidParameterCheck(e.savedQuery,"DynamicsWebApi."+t,"request.savedQuery")),e.userQuery&&u.push("userQuery="+a.guidParameterCheck(e.userQuery,"DynamicsWebApi."+t,"request.userQuery")),e.count&&(a.boolParameterCheck(e.count,"DynamicsWebApi."+t,"request.count"),u.push("$count="+e.count)),e.top&&e.top>0&&(a.numberParameterCheck(e.top,"DynamicsWebApi."+t,"request.top"),u.push("$top="+e.top)),null!=e.orderBy&&e.orderBy.length&&(a.arrayParameterCheck(e.orderBy,"DynamicsWebApi."+t,"request.orderBy"),u.push("$orderby="+e.orderBy.join(",")));var f=o(e,t,s);if(f.length&&(c.Prefer=f),null!=e.ifmatch&&null!=e.ifnonematch)throw new Error("DynamicsWebApi."+t+". Either one of request.ifmatch or request.ifnonematch parameters should be used in a call, not both.");if(e.ifmatch&&(a.stringParameterCheck(e.ifmatch,"DynamicsWebApi."+t,"request.ifmatch"),c["If-Match"]=e.ifmatch),e.ifnonematch&&(a.stringParameterCheck(e.ifnonematch,"DynamicsWebApi."+t,"request.ifnonematch"),c["If-None-Match"]=e.ifnonematch),e.impersonate&&(a.stringParameterCheck(e.impersonate,"DynamicsWebApi."+t,"request.impersonate"),c.MSCRMCallerID=a.guidParameterCheck(e.impersonate,"DynamicsWebApi."+t,"request.impersonate")),e.token&&(a.stringParameterCheck(e.token,"DynamicsWebApi."+t,"request.token"),c.Authorization="Bearer "+e.token),e.duplicateDetection&&(a.boolParameterCheck(e.duplicateDetection,"DynamicsWebApi."+t,"request.duplicateDetection"),c["MSCRM.SuppressDuplicateDetection"]="false"),e.entity&&a.parameterCheck(e.entity,"DynamicsWebApi."+t,"request.entity"),e.data&&a.parameterCheck(e.data,"DynamicsWebApi."+t,"request.data"),e.noCache&&(a.boolParameterCheck(e.noCache,"DynamicsWebApi."+t,"request.noCache"),c["Cache-Control"]="no-cache"),e.mergeLabels&&(a.boolParameterCheck(e.mergeLabels,"DynamicsWebApi."+t,"request.mergeLabels"),c["MSCRM.MergeLabels"]="true"),e.expand&&e.expand.length)if(a.stringOrArrayParameterCheck(e.expand,"DynamicsWebApi."+t,"request.expand"),"string"==typeof e.expand)u.push("$expand="+e.expand);else{for(var y=[],d=0;d1&&(n+=",",r+="&"),n+=a+"=@p"+i,r+="@p"+i+"="+("string"==typeof o?"'"+o+"'":o)}return"("+n+")?"+r}return"()"}},function(e,t,n){var r=n(0),i=n(1);e.exports=function(e,t,n){var a=e.returnRepresentation,o=e.includeAnnotations,s=e.maxPageSize;if(e.prefer&&e.prefer.length){i.stringOrArrayParameterCheck(e.prefer,"DynamicsWebApi."+t,"request.prefer");var c=e.prefer;"string"==typeof c&&(c=c.split(","));for(var u in c){var l=c[u].trim();l===r.Prefer.ReturnRepresentation?a=!0:l.startsWith("odata.include-annotations=")?o=l.replace("odata.include-annotations=","").replace(/"/g,""):l.startsWith("odata.maxpagesize=")&&(s=l.replace("odata.maxpagesize=","").replace(/"/g,""))}}n&&(null==a&&(a=n.returnRepresentation),o=o?o:n.includeAnnotations,s=s?s:n.maxPageSize);var c=[];return a&&(i.boolParameterCheck(a,"DynamicsWebApi."+t,"request.returnRepresentation"),c.push(r.Prefer.ReturnRepresentation)),o&&(i.stringParameterCheck(o,"DynamicsWebApi."+t,"request.includeAnnotations"),c.push('odata.include-annotations="'+o+'"')),s&&s>0&&(i.numberParameterCheck(s,"DynamicsWebApi."+t,"request.maxPageSize"),c.push("odata.maxpagesize="+s)),c.join(",")}},function(e,t){e.exports=function(e){var t=/\/(\w+)\(([0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12})/i.exec(e["@odata.id"]);return{id:t[2],collection:t[1],oDataContext:e["@odata.context"]}}},function(e,t){e.exports=function(e,t){e=e?e:"",t=t?t:1,e=unescape(unescape(e));var n=/pagingcookie="()/.exec(e);if(null!=n){var r=parseInt(n[2]);return{cookie:n[1].replace(//g,">").replace(/\"/g,"'").replace(/\'/g,"""),page:r,nextPage:r+1}}return{cookie:"",page:t,nextPage:t+1}}},function(e,t,n){function r(e){var t={webApiVersion:"8.0",webApiUrl:null,impersonate:null,onTokenRefresh:null,includeAnnotations:null,maxPageSize:null,returnRepresentation:null};e||(e=t),this.setConfig=function(e){e.webApiVersion&&(o.stringParameterCheck(e.webApiVersion,"DynamicsWebApi.setConfig","config.webApiVersion"),t.webApiVersion=e.webApiVersion),e.webApiUrl?(o.stringParameterCheck(e.webApiUrl,"DynamicsWebApi.setConfig","config.webApiUrl"),t.webApiUrl=e.webApiUrl):t.webApiUrl=a.initWebApiUrl(t.webApiVersion),e.impersonate&&(t.impersonate=o.guidParameterCheck(e.impersonate,"DynamicsWebApi.setConfig","config.impersonate")),e.onTokenRefresh&&(o.callbackParameterCheck(e.onTokenRefresh,"DynamicsWebApi.setConfig","config.onTokenRefresh"),t.onTokenRefresh=e.onTokenRefresh),e.includeAnnotations&&(o.stringParameterCheck(e.includeAnnotations,"DynamicsWebApi.setConfig","config.includeAnnotations"),t.includeAnnotations=e.includeAnnotations),e.maxPageSize&&(o.numberParameterCheck(e.maxPageSize,"DynamicsWebApi.setConfig","config.maxPageSize"),t.maxPageSize=e.maxPageSize),e.returnRepresentation&&(o.boolParameterCheck(e.returnRepresentation,"DynamicsWebApi.setConfig","config.returnRepresentation"),t.returnRepresentation=e.returnRepresentation),e.useEntityNames&&(o.boolParameterCheck(e.useEntityNames,"DynamicsWebApi.setConfig","config.useEntityNames"),t.useEntityNames=e.useEntityNames)},this.setConfig(e);var n=function(e,n,r){return new Promise(function(i,a){s.makeRequest(e,n,r,t,i,a)})};this.createRequest=function(e){return o.parameterCheck(e,"DynamicsWebApi.create","request"),n("POST",e,"create").then(function(e){if(e.data)return e.data;var t=e.headers["OData-EntityId"]?e.headers["OData-EntityId"]:e.headers["odata-entityid"];return/([0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12})\)$/i.exec(t)[1]})},this.create=function(e,t,n,r){o.parameterCheck(e,"DynamicsWebApi.create","object"),o.stringParameterCheck(t,"DynamicsWebApi.create","collection"),n&&o.stringOrArrayParameterCheck(n,"DynamicsWebApi.create","prefer"),r&&o.arrayParameterCheck(r,"DynamicsWebApi.create","select");var i={collection:t,select:r,prefer:n,entity:e};return this.createRequest(i)},this.retrieveRequest=function(e){o.parameterCheck(e,"DynamicsWebApi.retrieve","request");var t=e.select;return n("GET",e,"retrieve").then(function(e){return null!=t&&1==t.length&&t[0].endsWith("/$ref")&&null!=e.data["@odata.id"]?a.convertToReferenceObject(e.data):e.data})},this.retrieve=function(e,t,n,r){o.stringParameterCheck(e,"DynamicsWebApi.retrieve","key"),e=o.keyParameterCheck(e,"DynamicsWebApi.retrieve","key"),o.stringParameterCheck(t,"DynamicsWebApi.retrieve","collection"),n&&n.length&&o.arrayParameterCheck(n,"DynamicsWebApi.retrieve","select"),r&&r.length&&o.stringOrArrayParameterCheck(r,"DynamicsWebApi.retrieve","expand");var i={collection:t,key:e,select:n,expand:r};return this.retrieveRequest(i)},this.updateRequest=function(e){o.parameterCheck(e,"DynamicsWebApi.update","request"),null==e.ifmatch&&(e.ifmatch="*");var t=e.collection.indexOf("EntityDefinitions")>-1||e.collection.indexOf("RelationshipDefinitions")>-1?"PUT":"PATCH",r=e.ifmatch;return n(t,e,"update").then(function(e){return!e.data||e.data}).catch(function(e){if(r&&412==e.status)return!1;throw e})},this.update=function(e,t,n,r,i){o.stringParameterCheck(e,"DynamicsWebApi.update","key"),e=o.keyParameterCheck(e,"DynamicsWebApi.update","key"),o.parameterCheck(n,"DynamicsWebApi.update","object"),o.stringParameterCheck(t,"DynamicsWebApi.update","collection"),r&&o.stringOrArrayParameterCheck(r,"DynamicsWebApi.update","prefer"),i&&o.arrayParameterCheck(i,"DynamicsWebApi.update","select");var a={collection:t,key:e,select:i,prefer:r,entity:n};return this.updateRequest(a)},this.updateSingleProperty=function(e,t,r,i,a){o.stringParameterCheck(e,"DynamicsWebApi.updateSingleProperty","key"),e=o.keyParameterCheck(e,"DynamicsWebApi.updateSingleProperty","key"),o.parameterCheck(r,"DynamicsWebApi.updateSingleProperty","keyValuePair"),o.stringParameterCheck(t,"DynamicsWebApi.updateSingleProperty","collection");var s=Object.keys(r)[0],c=r[s];return i&&o.stringOrArrayParameterCheck(i,"DynamicsWebApi.updateSingleProperty","prefer"),a&&o.arrayParameterCheck(a,"DynamicsWebApi.updateSingleProperty","select"),n("PUT",{collection:t,key:e,select:a,prefer:i,navigationProperty:s,data:{value:c}},"updateSingleProperty").then(function(e){if(e.data)return e.data})},this.deleteRequest=function(e){o.parameterCheck(e,"DynamicsWebApi.delete","request");var t=e.ifmatch;return n("DELETE",e,"delete").then(function(){return!0}).catch(function(e){if(t&&412==e.status)return!1;throw e})},this.deleteRecord=function(e,t,r){return o.stringParameterCheck(t,"DynamicsWebApi.deleteRecord","collection"),null!=r&&o.stringParameterCheck(r,"DynamicsWebApi.deleteRecord","propertyName"),n("DELETE",{navigationProperty:r,collection:t,key:e},"deleteRecord").then(function(){})},this.upsertRequest=function(e){o.parameterCheck(e,"DynamicsWebApi.upsert","request");var t=e.ifnonematch,r=e.ifmatch;return n("PATCH",e,"upsert").then(function(e){if(e.headers["OData-EntityId"]||e.headers["odata-entityid"]){var t=e.headers["OData-EntityId"]?e.headers["OData-EntityId"]:e.headers["odata-entityid"];return/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(t)[0]}if(e.data)return e.data}).catch(function(e){if(!(t&&412==e.status||r&&404==e.status))throw e})},this.upsert=function(e,t,n,r,i){o.stringParameterCheck(e,"DynamicsWebApi.upsert","key"),e=o.keyParameterCheck(e,"DynamicsWebApi.upsert","key"),o.parameterCheck(n,"DynamicsWebApi.upsert","object"),o.stringParameterCheck(t,"DynamicsWebApi.upsert","collection"),r&&o.stringOrArrayParameterCheck(r,"DynamicsWebApi.upsert","prefer"),i&&o.arrayParameterCheck(i,"DynamicsWebApi.upsert","select");var a={collection:t,key:e,select:i,prefer:r,entity:n};return this.upsertRequest(a)};var c=function(e,t){t&&(o.stringParameterCheck(t,"DynamicsWebApi.retrieveMultiple","nextPageLink"),e.url=t);var r=e.count;return n("GET",e,"retrieveMultiple").then(function(e){return r&&(e.data.oDataCount=e.data.oDataCount||0),e.data})};this.retrieveMultipleRequest=c;var u=function(e,t,n){var n=n||[];return c(e,t).then(function(t){return n=n.concat(t.value),t.oDataNextLink?u(e,t.oDataNextLink,n):{value:n}})};this.retrieveAllRequest=function(e){return u(e)},this.count=function(e,t){if(null==t||null!=t&&!t.length){return n("GET",{collection:e,navigationProperty:"$count"},"count").then(function(e){return e.data?parseInt(e.data):0})}return this.retrieveMultipleRequest({collection:e,filter:t,count:!0},null).then(function(e){return e.oDataCount?e.oDataCount:0})},this.countAll=function(e,t,n){return u({collection:e,filter:t,select:n}).then(function(e){return e&&e.value?e.value.length:0})},this.retrieveMultiple=function(e,t,n,r){return this.retrieveMultipleRequest({collection:e,select:t,filter:n},r)},this.retrieveAll=function(e,t,n){return u({collection:e,select:t,filter:n})};var l=function(e,t,r,s,c,u){o.stringParameterCheck(t,"DynamicsWebApi.executeFetchXml","fetchXml"),s=s||1,o.numberParameterCheck(s,"DynamicsWebApi.executeFetchXml","pageNumber");var l='$1 page="'+s+'"';return null!=c&&(o.stringParameterCheck(c,"DynamicsWebApi.executeFetchXml","pagingCookie"),l+=' paging-cookie="'+c+'"'),t=t.replace(/^(n.length)&&(t=n.length),t-=e.length;var i=n.lastIndexOf(e,t);return i!==-1&&i===t},String.prototype.startsWith=function(e,t){return t=t||0,this.substr(t,e.length)===e}},function(e,t,n){function i(e){return void 0===e||"unknown"==typeof e||null==e}function r(){var e=(new Date).getTime();return"undefined"!=typeof performance&&"function"==typeof performance.now&&(e+=performance.now()),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"===t?n:3&n|8).toString(16)})}function a(){if("undefined"!=typeof GetGlobalContext)return GetGlobalContext();if("undefined"!=typeof Xrm){if(!i(Xrm.Utility)&&!i(Xrm.Utility.getGlobalContext))return Xrm.Utility.getGlobalContext();if(!i(Xrm.Page)&&!i(Xrm.Page.context))return Xrm.Page.context}throw new Error("Xrm Context is not available. In most cases, it can be resolved by adding a reference to a ClientGlobalContext.js.aspx. Please refer to MSDN documentation for more details.")}function o(){var e=a();if(e){var t=e.getClientUrl();return t.match(/\/$/)&&(t=t.substring(0,t.length-1)),t}return""}function s(e){return o()+"/api/data/v"+e+"/"}function c(){return"undefined"!=typeof Xrm?Xrm.Internal:null}var u={buildFunctionParameters:n(10),getFetchXmlPagingCookie:n(13),convertToReferenceObject:n(12),isNull:i,generateUUID:r,getXrmContext:a,getXrmInternal:c,getClientUrl:o,initWebApiUrl:s};e.exports=u},function(e,t,n){function i(e){var t=h.getXrmInternal();if(!h.isNull(t)){var n=t.getEntitySetName(e);return n||e}var n=null;if(!h.isNull(p)&&(n=p[e],h.isNull(n)))for(var i in p)if(p[i]==e)return e;return n}function r(e){return e.Accept="application/json",e["OData-MaxVersion"]="4.0",e["OData-Version"]="4.0",e["Content-Type"]="application/json; charset=utf-8",e}function a(e,t){var n;return e&&(n=JSON.stringify(e,function(e,n){if(e.endsWith("@odata.bind")||e.endsWith("@odata.id")){if("string"==typeof n){if(/\(\{[\w\d-]+\}\)/g.test(n)&&(n=n.replace(/(.+)\(\{([\w\d-]+)\}\)/g,"$1($2)")),t.useEntityNames){var r=/([\w_]+)(\([\d\w-]+\))$/,a=r.exec(n);if(a.length>2){var o=i(a[1]);h.isNull(o)||(n=n.replace(r,o+"$2"))}}n.startsWith(t.webApiUrl)||(n=t.webApiUrl+n.replace(/^\\/,""))}}else(e.startsWith("oData")||e.endsWith("_Formatted")||e.endsWith("_NavigationProperty")||e.endsWith("_LogicalName"))&&(n=void 0);return n}),n=n.replace(/[\u007F-\uFFFF]/g,function(e){return"\\u"+("0000"+e.charCodeAt(0).toString(16)).substr(-4)})),n}function o(e,t,i,o,s,c,u,l){s||(s={}),s=r(s);var p=a(o,i);if(t.length>2e3){var m="dwa_batch_"+h.generateUUID(),f=[];f.push("--"+m),f.push("Content-Type: application/http"),f.push("Content-Transfer-Encoding: binary\n"),f.push(e+" "+i.webApiUrl+t+" HTTP/1.1");for(var y in s)f.push(y+": "+s[y]),"Authorization"!=y&&delete s[y];f.push("\n--"+m+"--"),p=f.join("\n"),s=r(s),s["Content-Type"]="multipart/mixed;boundary="+m,t="$batch",e="POST"}i.impersonate&&!s.MSCRMCallerID&&(s.MSCRMCallerID=i.impersonate);var d;d=n(8);var g=function(n){n&&(s||(s={}),s.Authorization="Bearer "+(n.hasOwnProperty("accessToken")?n.accessToken:n)),d(e,i.webApiUrl+t,p,s,c,u,l)};i.onTokenRefresh&&(!s||s&&!s.Authorization)?i.onTokenRefresh(g):g()}function s(e,t,n,r){var a=function(t){p={};for(var r=0;r-1}function u(e,t,n,r){if(c(e)||h.isNull(e))return void n(e);if(e=e.toLowerCase(),!t.useEntityNames)return void n(e);try{var a=i(e);h.isNull(a)?s(e,t,n,r):n(a)}catch(e){r({message:"Unable to fetch Collection Names. Error: "+e.message})}}function l(e,t,n,i,r,a){var s=function(s){t.collection=s;var c=m.convertRequest(t,n,i);o(e,c.url,i,t.data||t.entity,c.headers,r,a,c.async)};u(t.collection,i,s,a)}var p,h=(n(0),n(3)),m=n(9);e.exports={sendRequest:o,makeRequest:l,getCollectionName:i}},function(e,t){e.exports=function(e,t){var n;return"string"==typeof t&&(n=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:Z|[-+]\d{2}:\d{2})$/.exec(t))?new Date(Date.UTC(+n[1],+n[2]-1,+n[3],+n[4],+n[5],+n[6])):t}},function(e,t,n){function i(e){var t=e.substr(0,e.indexOf("\r\n")),n=e.split(t);n.shift(),n.pop();for(var i=[],r=0;r-1?i(e)[0]:JSON.parse(e,s),t=a(t)),t}},function(e,t){e.exports=function(e){var t={};if(!e)return t;for(var n=e.split("\r\n"),i=0,r=n.length;i0&&(t[a.substring(0,o)]=a.substring(o+2))}return t}},function(e,t,n){var i=n(6),r=n(7),a=function(e,t,n,a,o,s,c){var u=new XMLHttpRequest;u.open(e,t,c);for(var l in a)u.setRequestHeader(l,a[l]);u.onreadystatechange=function(){if(4===u.readyState){switch(u.status){case 200:case 201:case 204:case 304:o({data:i(u.responseText),headers:r(u.getAllResponseHeaders()),status:u.status});break;default:var e;try{e=JSON.parse(u.response).error}catch(t){e=u.response.length>0?{message:u.response}:{message:"Unexpected Error"}}e.status=u.status,e.statusText=u.statusText,s(e)}u=null}},u.onerror=function(){s({message:"Network Error"}),u=null},u.ontimeout=function(e){s({message:"Request Timed Out"}),u=null},n?u.send(n):u.send()};e.exports=a},function(e,t,n){function i(e,t,n,r,s){var c={},u=[];if(r=null!=r?r:"&",e){if(e.navigationProperty){if(a.stringParameterCheck(e.navigationProperty,"DynamicsWebApi."+t,"request.navigationProperty"),n+="/"+e.navigationProperty,e.navigationPropertyKey){n+="("+a.keyParameterCheck(e.navigationPropertyKey,"DynamicsWebApi."+t,"request.navigationPropertyKey")+")"}"Attributes"===e.navigationProperty&&e.metadataAttributeType&&(a.stringParameterCheck(e.metadataAttributeType,"DynamicsWebApi."+t,"request.metadataAttributeType"),n+="/"+e.metadataAttributeType)}if(null!=e.select&&e.select.length&&(a.arrayParameterCheck(e.select,"DynamicsWebApi."+t,"request.select"),"retrieve"==t&&1==e.select.length&&e.select[0].endsWith("/$ref")?n+="/"+e.select[0]:(e.select[0].startsWith("/")&&"retrieve"==t&&(null==e.navigationProperty?n+=e.select.shift():e.select.shift()),e.select.length&&u.push("$select="+e.select.join(",")))),e.filter){a.stringParameterCheck(e.filter,"DynamicsWebApi."+t,"request.filter");for(var l=/[^"']{([\w\d]{8}[-]?(?:[\w\d]{4}[-]?){3}[\w\d]{12})}(?:[^"']|$)/g,p=e.filter;null!==(m=l.exec(p));){m.index===l.lastIndex&®ex.lastIndex++;var h=m[0].endsWith(")")?")":" ";p=p.replace(m[0]," "+m[1]+h)}u.push("$filter="+encodeURIComponent(p))}e.savedQuery&&u.push("savedQuery="+a.guidParameterCheck(e.savedQuery,"DynamicsWebApi."+t,"request.savedQuery")),e.userQuery&&u.push("userQuery="+a.guidParameterCheck(e.userQuery,"DynamicsWebApi."+t,"request.userQuery")),e.count&&(a.boolParameterCheck(e.count,"DynamicsWebApi."+t,"request.count"),u.push("$count="+e.count)),e.top&&e.top>0&&(a.numberParameterCheck(e.top,"DynamicsWebApi."+t,"request.top"),u.push("$top="+e.top)),null!=e.orderBy&&e.orderBy.length&&(a.arrayParameterCheck(e.orderBy,"DynamicsWebApi."+t,"request.orderBy"),u.push("$orderby="+e.orderBy.join(",")));var f=o(e,t,s);if(f.length&&(c.Prefer=f),null!=e.ifmatch&&null!=e.ifnonematch)throw new Error("DynamicsWebApi."+t+". Either one of request.ifmatch or request.ifnonematch parameters should be used in a call, not both.");if(e.ifmatch&&(a.stringParameterCheck(e.ifmatch,"DynamicsWebApi."+t,"request.ifmatch"),c["If-Match"]=e.ifmatch),e.ifnonematch&&(a.stringParameterCheck(e.ifnonematch,"DynamicsWebApi."+t,"request.ifnonematch"),c["If-None-Match"]=e.ifnonematch),e.impersonate&&(a.stringParameterCheck(e.impersonate,"DynamicsWebApi."+t,"request.impersonate"),c.MSCRMCallerID=a.guidParameterCheck(e.impersonate,"DynamicsWebApi."+t,"request.impersonate")),e.token&&(a.stringParameterCheck(e.token,"DynamicsWebApi."+t,"request.token"),c.Authorization="Bearer "+e.token),e.duplicateDetection&&(a.boolParameterCheck(e.duplicateDetection,"DynamicsWebApi."+t,"request.duplicateDetection"),c["MSCRM.SuppressDuplicateDetection"]="false"),e.entity&&a.parameterCheck(e.entity,"DynamicsWebApi."+t,"request.entity"),e.data&&a.parameterCheck(e.data,"DynamicsWebApi."+t,"request.data"),e.noCache&&(a.boolParameterCheck(e.noCache,"DynamicsWebApi."+t,"request.noCache"),c["Cache-Control"]="no-cache"),e.mergeLabels&&(a.boolParameterCheck(e.mergeLabels,"DynamicsWebApi."+t,"request.mergeLabels"),c["MSCRM.MergeLabels"]="true"),e.expand&&e.expand.length)if(a.stringOrArrayParameterCheck(e.expand,"DynamicsWebApi."+t,"request.expand"),"string"==typeof e.expand)u.push("$expand="+e.expand);else{for(var y=[],d=0;d1&&(n+=",",i+="&"),n+=a+"=@p"+r,i+="@p"+r+"="+("string"==typeof o?"'"+o+"'":o)}return"("+n+")?"+i}return"()"}},function(e,t,n){var i=n(0),r=n(1);e.exports=function(e,t,n){var a,o=e.returnRepresentation,s=e.includeAnnotations,c=e.maxPageSize;if(e.prefer&&e.prefer.length){r.stringOrArrayParameterCheck(e.prefer,"DynamicsWebApi."+t,"request.prefer"),a=e.prefer,"string"==typeof a&&(a=a.split(","));for(var u in a){var l=a[u].trim();l===i.Prefer.ReturnRepresentation?o=!0:l.startsWith("odata.include-annotations=")?s=l.replace("odata.include-annotations=","").replace(/"/g,""):l.startsWith("odata.maxpagesize=")&&(c=l.replace("odata.maxpagesize=","").replace(/"/g,""))}}return a=[],n&&(null==o&&(o=n.returnRepresentation),s=s?s:n.includeAnnotations,c=c?c:n.maxPageSize),o&&(r.boolParameterCheck(o,"DynamicsWebApi."+t,"request.returnRepresentation"),a.push(i.Prefer.ReturnRepresentation)),s&&(r.stringParameterCheck(s,"DynamicsWebApi."+t,"request.includeAnnotations"),a.push('odata.include-annotations="'+s+'"')),c&&c>0&&(r.numberParameterCheck(c,"DynamicsWebApi."+t,"request.maxPageSize"),a.push("odata.maxpagesize="+c)),a.join(",")}},function(e,t){e.exports=function(e){var t=/\/(\w+)\(([0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12})/i.exec(e["@odata.id"]);return{id:t[2],collection:t[1],oDataContext:e["@odata.context"]}}},function(e,t){e.exports=function(e,t){e=e?e:"",t=t?t:1,e=unescape(unescape(e));var n=/pagingcookie="()/.exec(e);if(null!=n){var i=parseInt(n[2]);return{cookie:n[1].replace(//g,">").replace(/\"/g,"'").replace(/\'/g,"""),page:i,nextPage:i+1}}return{cookie:"",page:t,nextPage:t+1}}},function(e,t,n){function i(e){var t={webApiVersion:"8.0",webApiUrl:null,impersonate:null,onTokenRefresh:null,includeAnnotations:null,maxPageSize:null,returnRepresentation:null};e||(e=t),this.setConfig=function(e){e.webApiVersion&&(o.stringParameterCheck(e.webApiVersion,"DynamicsWebApi.setConfig","config.webApiVersion"),t.webApiVersion=e.webApiVersion),e.webApiUrl?(o.stringParameterCheck(e.webApiUrl,"DynamicsWebApi.setConfig","config.webApiUrl"),t.webApiUrl=e.webApiUrl):t.webApiUrl=a.initWebApiUrl(t.webApiVersion),e.impersonate&&(t.impersonate=o.guidParameterCheck(e.impersonate,"DynamicsWebApi.setConfig","config.impersonate")),e.onTokenRefresh&&(o.callbackParameterCheck(e.onTokenRefresh,"DynamicsWebApi.setConfig","config.onTokenRefresh"),t.onTokenRefresh=e.onTokenRefresh),e.includeAnnotations&&(o.stringParameterCheck(e.includeAnnotations,"DynamicsWebApi.setConfig","config.includeAnnotations"),t.includeAnnotations=e.includeAnnotations),e.maxPageSize&&(o.numberParameterCheck(e.maxPageSize,"DynamicsWebApi.setConfig","config.maxPageSize"),t.maxPageSize=e.maxPageSize),e.returnRepresentation&&(o.boolParameterCheck(e.returnRepresentation,"DynamicsWebApi.setConfig","config.returnRepresentation"),t.returnRepresentation=e.returnRepresentation),e.useEntityNames&&(o.boolParameterCheck(e.useEntityNames,"DynamicsWebApi.setConfig","config.useEntityNames"),t.useEntityNames=e.useEntityNames)},this.setConfig(e);var n=function(e,n,i){return new Promise(function(r,a){s.makeRequest(e,n,i,t,r,a)})};this.createRequest=function(e){return o.parameterCheck(e,"DynamicsWebApi.create","request"),n("POST",e,"create").then(function(e){if(e.data)return e.data;var t=e.headers["OData-EntityId"]?e.headers["OData-EntityId"]:e.headers["odata-entityid"];return/([0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12})\)$/i.exec(t)[1]})},this.create=function(e,t,n,i){o.parameterCheck(e,"DynamicsWebApi.create","object"),o.stringParameterCheck(t,"DynamicsWebApi.create","collection"),n&&o.stringOrArrayParameterCheck(n,"DynamicsWebApi.create","prefer"),i&&o.arrayParameterCheck(i,"DynamicsWebApi.create","select");var r={collection:t,select:i,prefer:n,entity:e};return this.createRequest(r)},this.retrieveRequest=function(e){o.parameterCheck(e,"DynamicsWebApi.retrieve","request");var t=e.select;return n("GET",e,"retrieve").then(function(e){return null!=t&&1===t.length&&t[0].endsWith("/$ref")&&null!=e.data["@odata.id"]?a.convertToReferenceObject(e.data):e.data})},this.retrieve=function(e,t,n,i){o.stringParameterCheck(e,"DynamicsWebApi.retrieve","key"),e=o.keyParameterCheck(e,"DynamicsWebApi.retrieve","key"),o.stringParameterCheck(t,"DynamicsWebApi.retrieve","collection"),n&&n.length&&o.arrayParameterCheck(n,"DynamicsWebApi.retrieve","select"),i&&i.length&&o.stringOrArrayParameterCheck(i,"DynamicsWebApi.retrieve","expand");var r={collection:t,key:e,select:n,expand:i};return this.retrieveRequest(r)},this.updateRequest=function(e){o.parameterCheck(e,"DynamicsWebApi.update","request"),null==e.ifmatch&&(e.ifmatch="*");var t=/EntityDefinitions|RelationshipDefinitions|GlobalOptionSetDefinitions/.test(e.collection)?"PUT":"PATCH",i=e.ifmatch;return n(t,e,"update").then(function(e){return!e.data||e.data}).catch(function(e){if(i&&412===e.status)return!1;throw e})},this.update=function(e,t,n,i,r){o.stringParameterCheck(e,"DynamicsWebApi.update","key"),e=o.keyParameterCheck(e,"DynamicsWebApi.update","key"),o.parameterCheck(n,"DynamicsWebApi.update","object"),o.stringParameterCheck(t,"DynamicsWebApi.update","collection"),i&&o.stringOrArrayParameterCheck(i,"DynamicsWebApi.update","prefer"),r&&o.arrayParameterCheck(r,"DynamicsWebApi.update","select");var a={collection:t,key:e,select:r,prefer:i,entity:n};return this.updateRequest(a)},this.updateSingleProperty=function(e,t,i,r,a){o.stringParameterCheck(e,"DynamicsWebApi.updateSingleProperty","key"),e=o.keyParameterCheck(e,"DynamicsWebApi.updateSingleProperty","key"),o.parameterCheck(i,"DynamicsWebApi.updateSingleProperty","keyValuePair"),o.stringParameterCheck(t,"DynamicsWebApi.updateSingleProperty","collection");var s=Object.keys(i)[0],c=i[s];return r&&o.stringOrArrayParameterCheck(r,"DynamicsWebApi.updateSingleProperty","prefer"),a&&o.arrayParameterCheck(a,"DynamicsWebApi.updateSingleProperty","select"),n("PUT",{collection:t,key:e,select:a,prefer:r,navigationProperty:s,data:{value:c}},"updateSingleProperty").then(function(e){if(e.data)return e.data})},this.deleteRequest=function(e){o.parameterCheck(e,"DynamicsWebApi.delete","request");var t=e.ifmatch;return n("DELETE",e,"delete").then(function(){return!0}).catch(function(e){if(t&&412===e.status)return!1;throw e})},this.deleteRecord=function(e,t,i){return o.stringParameterCheck(t,"DynamicsWebApi.deleteRecord","collection"),null!=i&&o.stringParameterCheck(i,"DynamicsWebApi.deleteRecord","propertyName"),n("DELETE",{navigationProperty:i,collection:t,key:e},"deleteRecord").then(function(){})},this.upsertRequest=function(e){o.parameterCheck(e,"DynamicsWebApi.upsert","request");var t=e.ifnonematch,i=e.ifmatch;return n("PATCH",e,"upsert").then(function(e){if(e.headers["OData-EntityId"]||e.headers["odata-entityid"]){var t=e.headers["OData-EntityId"]?e.headers["OData-EntityId"]:e.headers["odata-entityid"];return/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(t)[0]}if(e.data)return e.data}).catch(function(e){if(!(t&&412===e.status||i&&404===e.status))throw e})},this.upsert=function(e,t,n,i,r){o.stringParameterCheck(e,"DynamicsWebApi.upsert","key"),e=o.keyParameterCheck(e,"DynamicsWebApi.upsert","key"),o.parameterCheck(n,"DynamicsWebApi.upsert","object"),o.stringParameterCheck(t,"DynamicsWebApi.upsert","collection"),i&&o.stringOrArrayParameterCheck(i,"DynamicsWebApi.upsert","prefer"),r&&o.arrayParameterCheck(r,"DynamicsWebApi.upsert","select");var a={collection:t,key:e,select:r,prefer:i,entity:n};return this.upsertRequest(a)};var c=function(e,t){t&&(o.stringParameterCheck(t,"DynamicsWebApi.retrieveMultiple","nextPageLink"),e.url=t);var i=e.count;return n("GET",e,"retrieveMultiple").then(function(e){return i&&(e.data.oDataCount=e.data.oDataCount||0),e.data})};this.retrieveMultipleRequest=c;var u=function(e,t,n){return n=n||[],c(e,t).then(function(t){return n=n.concat(t.value),t.oDataNextLink?u(e,t.oDataNextLink,n):{value:n}})};this.retrieveAllRequest=function(e){return u(e)},this.count=function(e,t){if(null==t||null!=t&&!t.length){return n("GET",{collection:e,navigationProperty:"$count"},"count").then(function(e){return e.data?parseInt(e.data):0})}return this.retrieveMultipleRequest({collection:e,filter:t,count:!0},null).then(function(e){return e.oDataCount?e.oDataCount:0})},this.countAll=function(e,t,n){return u({collection:e,filter:t,select:n}).then(function(e){return e&&e.value?e.value.length:0})},this.retrieveMultiple=function(e,t,n,i){return this.retrieveMultipleRequest({collection:e,select:t,filter:n},i)},this.retrieveAll=function(e,t,n){return u({collection:e,select:t,filter:n})};var l=function(e,t,i,s,c,u){o.stringParameterCheck(t,"DynamicsWebApi.executeFetchXml","fetchXml"),s=s||1,o.numberParameterCheck(s,"DynamicsWebApi.executeFetchXml","pageNumber");var l='$1 page="'+s+'"';return null!=c&&(o.stringParameterCheck(c,"DynamicsWebApi.executeFetchXml","pagingCookie"),l+=' paging-cookie="'+c+'"'),t=t.replace(/^(