Skip to content

Commit 7e6afe7

Browse files
copy request objects for batch request collection
1 parent fec184c commit 7e6afe7

File tree

6 files changed

+320
-236
lines changed

6 files changed

+320
-236
lines changed

dist/dynamics-web-api-callbacks.js

Lines changed: 105 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -358,109 +358,137 @@ module.exports = DWA;
358358
/***/ (function(module, exports, __webpack_require__) {
359359

360360
function isNull(value) {
361-
return typeof value === "undefined" || value == null;
361+
return typeof value === "undefined" || value == null;
362362
}
363363

364364
//https://stackoverflow.com/a/8809472
365365
function generateUUID() { // Public Domain/MIT
366-
var d = new Date().getTime();
367-
if (typeof performance !== 'undefined' && typeof performance.now === 'function') {
368-
d += performance.now(); //use high-precision timer if available
369-
}
370-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
371-
var r = (d + Math.random() * 16) % 16 | 0;
372-
d = Math.floor(d / 16);
373-
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
374-
});
366+
var d = new Date().getTime();
367+
if (typeof performance !== 'undefined' && typeof performance.now === 'function') {
368+
d += performance.now(); //use high-precision timer if available
369+
}
370+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
371+
var r = (d + Math.random() * 16) % 16 | 0;
372+
d = Math.floor(d / 16);
373+
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
374+
});
375375
}
376376

377377
function getXrmContext() {
378-
if (typeof GetGlobalContext !== 'undefined') {
379-
return GetGlobalContext();
380-
}
381-
else {
382-
if (typeof Xrm !== 'undefined') {
383-
//d365 v.9.0
384-
if (!isNull(Xrm.Utility) && !isNull(Xrm.Utility.getGlobalContext)) {
385-
return Xrm.Utility.getGlobalContext();
386-
}
387-
else if (!isNull(Xrm.Page) && !isNull(Xrm.Page.context)) {
388-
return Xrm.Page.context;
389-
}
390-
}
391-
}
378+
if (typeof GetGlobalContext !== 'undefined') {
379+
return GetGlobalContext();
380+
}
381+
else {
382+
if (typeof Xrm !== 'undefined') {
383+
//d365 v.9.0
384+
if (!isNull(Xrm.Utility) && !isNull(Xrm.Utility.getGlobalContext)) {
385+
return Xrm.Utility.getGlobalContext();
386+
}
387+
else if (!isNull(Xrm.Page) && !isNull(Xrm.Page.context)) {
388+
return Xrm.Page.context;
389+
}
390+
}
391+
}
392392

393-
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.');
393+
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.');
394394
}
395395

396396
function getClientUrl() {
397-
var context = getXrmContext();
397+
var context = getXrmContext();
398398

399-
var clientUrl = context.getClientUrl();
399+
var clientUrl = context.getClientUrl();
400400

401-
if (clientUrl.match(/\/$/)) {
402-
clientUrl = clientUrl.substring(0, clientUrl.length - 1);
403-
}
404-
return clientUrl;
401+
if (clientUrl.match(/\/$/)) {
402+
clientUrl = clientUrl.substring(0, clientUrl.length - 1);
403+
}
404+
return clientUrl;
405405
}
406406

407407
function initWebApiUrl(version) {
408-
return getClientUrl() + '/api/data/v' + version + '/';
408+
return getClientUrl() + '/api/data/v' + version + '/';
409409
}
410410

411411
function getXrmInternal() {
412-
//todo: Xrm.Internal namespace is not supported
413-
return typeof Xrm !== "undefined" ? Xrm.Internal : null;
412+
//todo: Xrm.Internal namespace is not supported
413+
return typeof Xrm !== "undefined" ? Xrm.Internal : null;
414414
}
415415

416416
function getXrmUtility() {
417-
return typeof Xrm !== "undefined" ? Xrm.Utility : null;
417+
return typeof Xrm !== "undefined" ? Xrm.Utility : null;
418418
}
419419

420-
var Utility = {
421-
/**
422-
* Builds parametes for a funciton. Returns '()' (if no parameters) or '([params])?[query]'
423-
*
424-
* @param {Object} [parameters] - Function's input parameters. Example: { param1: "test", param2: 3 }.
425-
* @returns {string}
426-
*/
427-
buildFunctionParameters: __webpack_require__(12),
428-
429-
/**
430-
* Parses a paging cookie returned in response
431-
*
432-
* @param {string} pageCookies - Page cookies returned in @Microsoft.Dynamics.CRM.fetchxmlpagingcookie.
433-
* @param {number} currentPageNumber - A current page number. Fix empty paging-cookie for complex fetch xmls.
434-
* @returns {{cookie: "", number: 0, next: 1}}
435-
*/
436-
getFetchXmlPagingCookie: __webpack_require__(15),
437-
438-
/**
439-
* Converts a response to a reference object
440-
*
441-
* @param {Object} responseData - Response object
442-
* @returns {ReferenceObject}
443-
*/
444-
convertToReferenceObject: __webpack_require__(14),
445-
446-
/**
447-
* Checks whether the value is JS Null.
448-
* @param {Object} value
449-
* @returns {boolean}
450-
*/
451-
isNull: isNull,
452-
453-
generateUUID: generateUUID,
454-
455-
getXrmContext: getXrmContext,
456-
457-
getXrmInternal: getXrmInternal,
420+
function _isObject(obj) {
421+
var type = typeof obj;
422+
return type === 'object' && !!obj;
423+
}
458424

459-
getXrmUtility: getXrmUtility,
425+
function copyObject(src) {
426+
var target = {};
427+
for (var prop in src) {
428+
if (src.hasOwnProperty(prop)) {
429+
// if the value is a nested object, recursively copy all its properties
430+
if (_isObject(src[prop])) {
431+
if (!Array.isArray(src[prop])) {
432+
target[prop] = copyObject(src[prop]);
433+
}
434+
else {
435+
target[prop] = src[prop].slice();
436+
}
460437

461-
getClientUrl: getClientUrl,
438+
} else {
439+
target[prop] = src[prop];
440+
}
441+
}
442+
}
443+
return target;
444+
}
462445

463-
initWebApiUrl: initWebApiUrl
446+
var Utility = {
447+
/**
448+
* Builds parametes for a funciton. Returns '()' (if no parameters) or '([params])?[query]'
449+
*
450+
* @param {Object} [parameters] - Function's input parameters. Example: { param1: "test", param2: 3 }.
451+
* @returns {string}
452+
*/
453+
buildFunctionParameters: __webpack_require__(12),
454+
455+
/**
456+
* Parses a paging cookie returned in response
457+
*
458+
* @param {string} pageCookies - Page cookies returned in @Microsoft.Dynamics.CRM.fetchxmlpagingcookie.
459+
* @param {number} currentPageNumber - A current page number. Fix empty paging-cookie for complex fetch xmls.
460+
* @returns {{ cookie: "", number: 0, next: 1 }}
461+
*/
462+
getFetchXmlPagingCookie: __webpack_require__(15),
463+
464+
/**
465+
* Converts a response to a reference object
466+
*
467+
* @param {Object} responseData - Response object
468+
* @returns {ReferenceObject}
469+
*/
470+
convertToReferenceObject: __webpack_require__(14),
471+
472+
/**
473+
* Checks whether the value is JS Null.
474+
* @param {Object} value
475+
* @returns {boolean}
476+
*/
477+
isNull: isNull,
478+
479+
generateUUID: generateUUID,
480+
481+
getXrmContext: getXrmContext,
482+
483+
getXrmInternal: getXrmInternal,
484+
485+
getXrmUtility: getXrmUtility,
486+
487+
getClientUrl: getClientUrl,
488+
489+
initWebApiUrl: initWebApiUrl,
490+
491+
copyObject: copyObject
464492
};
465493

466494
module.exports = Utility;
@@ -1156,7 +1184,7 @@ function makeRequest(method, request, functionName, config, responseParams, reso
11561184
//add response parameters to parse
11571185
_responseParseParams.push(responseParams || {});
11581186

1159-
_batchRequestCollection.push({ method: method, request: request });
1187+
_batchRequestCollection.push({ method: method, request: Utility.copyObject(request) });
11601188

11611189
//check for errors
11621190
RequestConverter.convertRequest(request, functionName, config);

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

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

0 commit comments

Comments
 (0)