@itentialopensource/adapter-servicenow 2.9.4 → 2.9.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CALLS.md +114 -0
- package/adapter.js +2102 -0
- package/entities/ChangeManagement/action.json +389 -0
- package/entities/ChangeManagement/schema.json +100 -1
- package/package.json +7 -7
- package/pronghorn.json +1285 -69
- package/report/adapterInfo.json +7 -7
- package/test/integration/adapterTestIntegration.js +484 -0
- package/test/unit/adapterTestUnit.js +673 -3
- package/refs?service=git-upload-pack +0 -0
package/adapter.js
CHANGED
|
@@ -11462,6 +11462,2108 @@ class Servicenow extends AdapterBaseCl {
|
|
|
11462
11462
|
return callback(null, errorObj);
|
|
11463
11463
|
}
|
|
11464
11464
|
}
|
|
11465
|
+
|
|
11466
|
+
/**
|
|
11467
|
+
* @function getChangeRequest
|
|
11468
|
+
* @pronghornType method
|
|
11469
|
+
* @name getChangeRequest
|
|
11470
|
+
* @summary Retrieves one or more change requests based on the specified criteria.
|
|
11471
|
+
*
|
|
11472
|
+
* @param {object} [sysparmQueryKeyValuePairs] - e.g. { number: 'CHG12345' }
|
|
11473
|
+
* @param {string} [sysparmQueryString] - e.g. number=CHG12345
|
|
11474
|
+
* @param {string} [order] - Field by which to sort the returned change requests.
|
|
11475
|
+
* @param {number} [sysparmOffset] - Starting record index for which to begin retrieving records. Use this value to paginate record retrieval. This functionality enables the retrieval of all records, regardl...(description truncated)
|
|
11476
|
+
* @param {string} [textSearch] - String to use to search all normal change request record fields. This search uses ServiceNow full text search platform functionality.
|
|
11477
|
+
* @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
|
|
11478
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
11479
|
+
* @return {object} results - An object containing the response of the action
|
|
11480
|
+
*
|
|
11481
|
+
* @route {POST} /getChangeRequest
|
|
11482
|
+
* @roles admin
|
|
11483
|
+
* @task true
|
|
11484
|
+
*/
|
|
11485
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
11486
|
+
getChangeRequest(sysparmQueryKeyValuePairs, sysparmQueryString, order, sysparmOffset, textSearch, iapMetadata, callback) {
|
|
11487
|
+
const meth = 'adapter-getChangeRequest';
|
|
11488
|
+
const origin = `${this.id}-${meth}`;
|
|
11489
|
+
log.trace(origin);
|
|
11490
|
+
|
|
11491
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
11492
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
11493
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11494
|
+
return callback(null, errorObj);
|
|
11495
|
+
}
|
|
11496
|
+
|
|
11497
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
11498
|
+
|
|
11499
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
11500
|
+
const queryParamsAvailable = { ...sysparmQueryKeyValuePairs, order, sysparmOffset, textSearch };
|
|
11501
|
+
const queryParams = {};
|
|
11502
|
+
const pathVars = [];
|
|
11503
|
+
const bodyVars = {};
|
|
11504
|
+
|
|
11505
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
11506
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
11507
|
+
if (thisKeyInQueryParamsAvailable !== 'sysparmQuery' && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined
|
|
11508
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
11509
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
11510
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
11511
|
+
}
|
|
11512
|
+
});
|
|
11513
|
+
|
|
11514
|
+
if (sysparmQueryString !== undefined && sysparmQueryString !== null && sysparmQueryString !== '') {
|
|
11515
|
+
queryParams.sysparmQuery = sysparmQueryString;
|
|
11516
|
+
} else if (sysparmQueryKeyValuePairs !== undefined && sysparmQueryKeyValuePairs !== null
|
|
11517
|
+
&& sysparmQueryKeyValuePairs.sysparmQuery !== undefined && sysparmQueryKeyValuePairs.sysparmQuery !== null
|
|
11518
|
+
&& sysparmQueryKeyValuePairs.sysparmQuery !== '') {
|
|
11519
|
+
queryParams.sysparmQuery = sysparmQueryKeyValuePairs.sysparmQuery;
|
|
11520
|
+
}
|
|
11521
|
+
|
|
11522
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
11523
|
+
// see adapter code documentation for more information on the request object's fields
|
|
11524
|
+
const reqObj = {
|
|
11525
|
+
payload: bodyVars,
|
|
11526
|
+
uriPathVars: pathVars,
|
|
11527
|
+
uriQuery: queryParams
|
|
11528
|
+
};
|
|
11529
|
+
|
|
11530
|
+
const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
|
|
11531
|
+
|
|
11532
|
+
// Merge and add new iapMetadata fields in reqObj
|
|
11533
|
+
if (iapMetadata && typeof iapMetadata === 'object') {
|
|
11534
|
+
Object.keys(iapMetadata).forEach((iapField) => {
|
|
11535
|
+
if (reqFields.includes(iapField) && iapMetadata[iapField]) {
|
|
11536
|
+
if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
|
|
11537
|
+
reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
|
|
11538
|
+
} else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
|
|
11539
|
+
reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
|
|
11540
|
+
} else {
|
|
11541
|
+
// Otherwise, add new iapMetadata fields to reqObj
|
|
11542
|
+
reqObj[iapField] = iapMetadata[iapField];
|
|
11543
|
+
}
|
|
11544
|
+
}
|
|
11545
|
+
});
|
|
11546
|
+
// Add iapMetadata to reqObj for further work
|
|
11547
|
+
reqObj.iapMetadata = iapMetadata;
|
|
11548
|
+
}
|
|
11549
|
+
|
|
11550
|
+
try {
|
|
11551
|
+
// Make the call -
|
|
11552
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
11553
|
+
return this.requestHandlerInst.identifyRequest('ChangeManagement', 'getChangeRequest', reqObj, true, (irReturnData, irReturnError) => {
|
|
11554
|
+
// if we received an error or their is no response on the results
|
|
11555
|
+
// return an error
|
|
11556
|
+
if (irReturnError) {
|
|
11557
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
11558
|
+
return callback(null, irReturnError);
|
|
11559
|
+
}
|
|
11560
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
11561
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getChangeRequest'], null, null, null);
|
|
11562
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11563
|
+
return callback(null, errorObj);
|
|
11564
|
+
}
|
|
11565
|
+
|
|
11566
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
11567
|
+
// return the response
|
|
11568
|
+
return callback(irReturnData, null);
|
|
11569
|
+
});
|
|
11570
|
+
} catch (ex) {
|
|
11571
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
11572
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11573
|
+
return callback(null, errorObj);
|
|
11574
|
+
}
|
|
11575
|
+
}
|
|
11576
|
+
|
|
11577
|
+
/**
|
|
11578
|
+
* @function createChangeRequestRecord
|
|
11579
|
+
* @pronghornType method
|
|
11580
|
+
* @name createChangeRequestRecord
|
|
11581
|
+
* @summary Creates a change request record based on the change request. Creating multiple change requests with
|
|
11582
|
+
*
|
|
11583
|
+
* @param {object} [sysparmQueryKeyValuePairs] - e.g. { number: 'CHG12345' }
|
|
11584
|
+
* @param {string} [sysparmQueryString] - e.g. number=CHG12345
|
|
11585
|
+
* @param {string} [changeModel] - Name of a change model listed in the Change Model [chg_model] table. Provided in the following format: chg_model=Normal.
|
|
11586
|
+
* @param {string} [encryptedFields] - List of comma-separated fields to encrypt. These fields are encrypted before they are stored in the associated record. When specified, the endpoint calls the GlideRecord ...(description truncated)
|
|
11587
|
+
* @param {string} [queryType] - Name of the change request type listed in the Choices [sys_choice] table. If the chg_model is also populated, this field is only used as a change categorization. Provided...(description truncated)
|
|
11588
|
+
* @param {object} body - body param
|
|
11589
|
+
* @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
|
|
11590
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
11591
|
+
* @return {object} results - An object containing the response of the action
|
|
11592
|
+
*
|
|
11593
|
+
* @route {POST} /createChangeRequestRecord
|
|
11594
|
+
* @roles admin
|
|
11595
|
+
* @task true
|
|
11596
|
+
*/
|
|
11597
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
11598
|
+
createChangeRequestRecord(sysparmQueryKeyValuePairs, sysparmQueryString, changeModel, encryptedFields, queryType, body, iapMetadata, callback) {
|
|
11599
|
+
const meth = 'adapter-createChangeRequestRecord';
|
|
11600
|
+
const origin = `${this.id}-${meth}`;
|
|
11601
|
+
log.trace(origin);
|
|
11602
|
+
|
|
11603
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
11604
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
11605
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11606
|
+
return callback(null, errorObj);
|
|
11607
|
+
}
|
|
11608
|
+
|
|
11609
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
11610
|
+
if (body === undefined || body === null || body === '') {
|
|
11611
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
|
|
11612
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11613
|
+
return callback(null, errorObj);
|
|
11614
|
+
}
|
|
11615
|
+
|
|
11616
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
11617
|
+
const queryParamsAvailable = { ...sysparmQueryKeyValuePairs, changeModel, encryptedFields, queryType };
|
|
11618
|
+
const queryParams = {};
|
|
11619
|
+
const pathVars = [];
|
|
11620
|
+
const bodyVars = body;
|
|
11621
|
+
|
|
11622
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
11623
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
11624
|
+
if (thisKeyInQueryParamsAvailable !== 'sysparmQuery' && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined
|
|
11625
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
11626
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
11627
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
11628
|
+
}
|
|
11629
|
+
});
|
|
11630
|
+
|
|
11631
|
+
if (sysparmQueryString !== undefined && sysparmQueryString !== null && sysparmQueryString !== '') {
|
|
11632
|
+
queryParams.sysparmQuery = sysparmQueryString;
|
|
11633
|
+
} else if (sysparmQueryKeyValuePairs !== undefined && sysparmQueryKeyValuePairs !== null
|
|
11634
|
+
&& sysparmQueryKeyValuePairs.sysparmQuery !== undefined && sysparmQueryKeyValuePairs.sysparmQuery !== null
|
|
11635
|
+
&& sysparmQueryKeyValuePairs.sysparmQuery !== '') {
|
|
11636
|
+
queryParams.sysparmQuery = sysparmQueryKeyValuePairs.sysparmQuery;
|
|
11637
|
+
}
|
|
11638
|
+
|
|
11639
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
11640
|
+
// see adapter code documentation for more information on the request object's fields
|
|
11641
|
+
const reqObj = {
|
|
11642
|
+
payload: bodyVars,
|
|
11643
|
+
uriPathVars: pathVars,
|
|
11644
|
+
uriQuery: queryParams
|
|
11645
|
+
};
|
|
11646
|
+
|
|
11647
|
+
const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
|
|
11648
|
+
|
|
11649
|
+
// Merge and add new iapMetadata fields in reqObj
|
|
11650
|
+
if (iapMetadata && typeof iapMetadata === 'object') {
|
|
11651
|
+
Object.keys(iapMetadata).forEach((iapField) => {
|
|
11652
|
+
if (reqFields.includes(iapField) && iapMetadata[iapField]) {
|
|
11653
|
+
if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
|
|
11654
|
+
reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
|
|
11655
|
+
} else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
|
|
11656
|
+
reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
|
|
11657
|
+
} else {
|
|
11658
|
+
// Otherwise, add new iapMetadata fields to reqObj
|
|
11659
|
+
reqObj[iapField] = iapMetadata[iapField];
|
|
11660
|
+
}
|
|
11661
|
+
}
|
|
11662
|
+
});
|
|
11663
|
+
// Add iapMetadata to reqObj for further work
|
|
11664
|
+
reqObj.iapMetadata = iapMetadata;
|
|
11665
|
+
}
|
|
11666
|
+
|
|
11667
|
+
try {
|
|
11668
|
+
// Make the call -
|
|
11669
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
11670
|
+
return this.requestHandlerInst.identifyRequest('ChangeManagement', 'createChangeRequestRecord', reqObj, true, (irReturnData, irReturnError) => {
|
|
11671
|
+
// if we received an error or their is no response on the results
|
|
11672
|
+
// return an error
|
|
11673
|
+
if (irReturnError) {
|
|
11674
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
11675
|
+
return callback(null, irReturnError);
|
|
11676
|
+
}
|
|
11677
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
11678
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['createChangeRequestRecord'], null, null, null);
|
|
11679
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11680
|
+
return callback(null, errorObj);
|
|
11681
|
+
}
|
|
11682
|
+
|
|
11683
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
11684
|
+
// return the response
|
|
11685
|
+
return callback(irReturnData, null);
|
|
11686
|
+
});
|
|
11687
|
+
} catch (ex) {
|
|
11688
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
11689
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11690
|
+
return callback(null, errorObj);
|
|
11691
|
+
}
|
|
11692
|
+
}
|
|
11693
|
+
|
|
11694
|
+
/**
|
|
11695
|
+
* @function getConfigurationItemSchedule
|
|
11696
|
+
* @pronghornType method
|
|
11697
|
+
* @name getConfigurationItemSchedule
|
|
11698
|
+
* @summary Enables retrieving available time slots by configuration item ID and duration, with an option to in
|
|
11699
|
+
*
|
|
11700
|
+
* @param {string} cmdbCiSysId - Sys_id of a record in the Configuration Items [cmdb_ci] table. This endpoint does not require a change request.
|
|
11701
|
+
* @param {number} [durationInSeconds] - Duration of change in seconds, that is, how much time is required to complete the change request task.
|
|
11702
|
+
* @param {string} [plannedStartTime] - Retrieve the available time slot start at or later than this time. If not provided, the system uses the current time as the start time. Time format: yyyy-mm-dd hh:mm:ss
|
|
11703
|
+
* @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
|
|
11704
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
11705
|
+
* @return {object} results - An object containing the response of the action
|
|
11706
|
+
*
|
|
11707
|
+
* @route {POST} /getConfigurationItemSchedule
|
|
11708
|
+
* @roles admin
|
|
11709
|
+
* @task true
|
|
11710
|
+
*/
|
|
11711
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
11712
|
+
getConfigurationItemSchedule(cmdbCiSysId, durationInSeconds, plannedStartTime, iapMetadata, callback) {
|
|
11713
|
+
const meth = 'adapter-getConfigurationItemSchedule';
|
|
11714
|
+
const origin = `${this.id}-${meth}`;
|
|
11715
|
+
log.trace(origin);
|
|
11716
|
+
|
|
11717
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
11718
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
11719
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11720
|
+
return callback(null, errorObj);
|
|
11721
|
+
}
|
|
11722
|
+
|
|
11723
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
11724
|
+
if (cmdbCiSysId === undefined || cmdbCiSysId === null || cmdbCiSysId === '') {
|
|
11725
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['cmdbCiSysId'], null, null, null);
|
|
11726
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11727
|
+
return callback(null, errorObj);
|
|
11728
|
+
}
|
|
11729
|
+
|
|
11730
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
11731
|
+
const queryParamsAvailable = { durationInSeconds, plannedStartTime };
|
|
11732
|
+
const queryParams = {};
|
|
11733
|
+
const pathVars = [cmdbCiSysId];
|
|
11734
|
+
const bodyVars = {};
|
|
11735
|
+
|
|
11736
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
11737
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
11738
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
11739
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
11740
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
11741
|
+
}
|
|
11742
|
+
});
|
|
11743
|
+
|
|
11744
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
11745
|
+
// see adapter code documentation for more information on the request object's fields
|
|
11746
|
+
const reqObj = {
|
|
11747
|
+
payload: bodyVars,
|
|
11748
|
+
uriPathVars: pathVars,
|
|
11749
|
+
uriQuery: queryParams
|
|
11750
|
+
};
|
|
11751
|
+
|
|
11752
|
+
const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
|
|
11753
|
+
|
|
11754
|
+
// Merge and add new iapMetadata fields in reqObj
|
|
11755
|
+
if (iapMetadata && typeof iapMetadata === 'object') {
|
|
11756
|
+
Object.keys(iapMetadata).forEach((iapField) => {
|
|
11757
|
+
if (reqFields.includes(iapField) && iapMetadata[iapField]) {
|
|
11758
|
+
if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
|
|
11759
|
+
reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
|
|
11760
|
+
} else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
|
|
11761
|
+
reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
|
|
11762
|
+
} else {
|
|
11763
|
+
// Otherwise, add new iapMetadata fields to reqObj
|
|
11764
|
+
reqObj[iapField] = iapMetadata[iapField];
|
|
11765
|
+
}
|
|
11766
|
+
}
|
|
11767
|
+
});
|
|
11768
|
+
// Add iapMetadata to reqObj for further work
|
|
11769
|
+
reqObj.iapMetadata = iapMetadata;
|
|
11770
|
+
}
|
|
11771
|
+
|
|
11772
|
+
try {
|
|
11773
|
+
// Make the call -
|
|
11774
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
11775
|
+
return this.requestHandlerInst.identifyRequest('ChangeManagement', 'getConfigurationItemSchedule', reqObj, true, (irReturnData, irReturnError) => {
|
|
11776
|
+
// if we received an error or their is no response on the results
|
|
11777
|
+
// return an error
|
|
11778
|
+
if (irReturnError) {
|
|
11779
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
11780
|
+
return callback(null, irReturnError);
|
|
11781
|
+
}
|
|
11782
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
11783
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getConfigurationItemSchedule'], null, null, null);
|
|
11784
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11785
|
+
return callback(null, errorObj);
|
|
11786
|
+
}
|
|
11787
|
+
|
|
11788
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
11789
|
+
// return the response
|
|
11790
|
+
return callback(irReturnData, null);
|
|
11791
|
+
});
|
|
11792
|
+
} catch (ex) {
|
|
11793
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
11794
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11795
|
+
return callback(null, errorObj);
|
|
11796
|
+
}
|
|
11797
|
+
}
|
|
11798
|
+
|
|
11799
|
+
/**
|
|
11800
|
+
* @function updateEmergencyChangeRequestById
|
|
11801
|
+
* @pronghornType method
|
|
11802
|
+
* @name updateEmergencyChangeRequestById
|
|
11803
|
+
* @summary Updates the emergency change request identified by the specified sys_id with the key-value pairs in
|
|
11804
|
+
*
|
|
11805
|
+
* @param {string} sysId - Sys_id of the change request to modify. Located in the [change_request] table.
|
|
11806
|
+
* @param {object} [sysparmQueryKeyValuePairs] - e.g. { number: 'CHG12345' }
|
|
11807
|
+
* @param {string} [sysparmQueryString] - e.g. number=CHG12345
|
|
11808
|
+
* @param {object} body - body param
|
|
11809
|
+
* @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
|
|
11810
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
11811
|
+
* @return {object} results - An object containing the response of the action
|
|
11812
|
+
*
|
|
11813
|
+
* @route {POST} /updateEmergencyChangeRequestById
|
|
11814
|
+
* @roles admin
|
|
11815
|
+
* @task true
|
|
11816
|
+
*/
|
|
11817
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
11818
|
+
updateEmergencyChangeRequestById(sysId, sysparmQueryKeyValuePairs, sysparmQueryString, body, iapMetadata, callback) {
|
|
11819
|
+
const meth = 'adapter-updateEmergencyChangeRequestById';
|
|
11820
|
+
const origin = `${this.id}-${meth}`;
|
|
11821
|
+
log.trace(origin);
|
|
11822
|
+
|
|
11823
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
11824
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
11825
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11826
|
+
return callback(null, errorObj);
|
|
11827
|
+
}
|
|
11828
|
+
|
|
11829
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
11830
|
+
if (sysId === undefined || sysId === null || sysId === '') {
|
|
11831
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['sysId'], null, null, null);
|
|
11832
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11833
|
+
return callback(null, errorObj);
|
|
11834
|
+
}
|
|
11835
|
+
if (body === undefined || body === null || body === '') {
|
|
11836
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
|
|
11837
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11838
|
+
return callback(null, errorObj);
|
|
11839
|
+
}
|
|
11840
|
+
|
|
11841
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
11842
|
+
const queryParamsAvailable = { ...sysparmQueryKeyValuePairs };
|
|
11843
|
+
const queryParams = {};
|
|
11844
|
+
const pathVars = [sysId];
|
|
11845
|
+
const bodyVars = body;
|
|
11846
|
+
|
|
11847
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
11848
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
11849
|
+
if (thisKeyInQueryParamsAvailable !== 'sysparmQuery' && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined
|
|
11850
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
11851
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
11852
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
11853
|
+
}
|
|
11854
|
+
});
|
|
11855
|
+
|
|
11856
|
+
if (sysparmQueryString !== undefined && sysparmQueryString !== null && sysparmQueryString !== '') {
|
|
11857
|
+
queryParams.sysparmQuery = sysparmQueryString;
|
|
11858
|
+
} else if (sysparmQueryKeyValuePairs !== undefined && sysparmQueryKeyValuePairs !== null
|
|
11859
|
+
&& sysparmQueryKeyValuePairs.sysparmQuery !== undefined && sysparmQueryKeyValuePairs.sysparmQuery !== null
|
|
11860
|
+
&& sysparmQueryKeyValuePairs.sysparmQuery !== '') {
|
|
11861
|
+
queryParams.sysparmQuery = sysparmQueryKeyValuePairs.sysparmQuery;
|
|
11862
|
+
}
|
|
11863
|
+
|
|
11864
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
11865
|
+
// see adapter code documentation for more information on the request object's fields
|
|
11866
|
+
const reqObj = {
|
|
11867
|
+
payload: bodyVars,
|
|
11868
|
+
uriPathVars: pathVars,
|
|
11869
|
+
uriQuery: queryParams
|
|
11870
|
+
};
|
|
11871
|
+
|
|
11872
|
+
const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
|
|
11873
|
+
|
|
11874
|
+
// Merge and add new iapMetadata fields in reqObj
|
|
11875
|
+
if (iapMetadata && typeof iapMetadata === 'object') {
|
|
11876
|
+
Object.keys(iapMetadata).forEach((iapField) => {
|
|
11877
|
+
if (reqFields.includes(iapField) && iapMetadata[iapField]) {
|
|
11878
|
+
if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
|
|
11879
|
+
reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
|
|
11880
|
+
} else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
|
|
11881
|
+
reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
|
|
11882
|
+
} else {
|
|
11883
|
+
// Otherwise, add new iapMetadata fields to reqObj
|
|
11884
|
+
reqObj[iapField] = iapMetadata[iapField];
|
|
11885
|
+
}
|
|
11886
|
+
}
|
|
11887
|
+
});
|
|
11888
|
+
// Add iapMetadata to reqObj for further work
|
|
11889
|
+
reqObj.iapMetadata = iapMetadata;
|
|
11890
|
+
}
|
|
11891
|
+
|
|
11892
|
+
try {
|
|
11893
|
+
// Make the call -
|
|
11894
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
11895
|
+
return this.requestHandlerInst.identifyRequest('ChangeManagement', 'updateEmergencyChangeRequestById', reqObj, true, (irReturnData, irReturnError) => {
|
|
11896
|
+
// if we received an error or their is no response on the results
|
|
11897
|
+
// return an error
|
|
11898
|
+
if (irReturnError) {
|
|
11899
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
11900
|
+
return callback(null, irReturnError);
|
|
11901
|
+
}
|
|
11902
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
11903
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['updateEmergencyChangeRequestById'], null, null, null);
|
|
11904
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11905
|
+
return callback(null, errorObj);
|
|
11906
|
+
}
|
|
11907
|
+
|
|
11908
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
11909
|
+
// return the response
|
|
11910
|
+
return callback(irReturnData, null);
|
|
11911
|
+
});
|
|
11912
|
+
} catch (ex) {
|
|
11913
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
11914
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11915
|
+
return callback(null, errorObj);
|
|
11916
|
+
}
|
|
11917
|
+
}
|
|
11918
|
+
|
|
11919
|
+
/**
|
|
11920
|
+
* @function getChangeModel
|
|
11921
|
+
* @pronghornType method
|
|
11922
|
+
* @name getChangeModel
|
|
11923
|
+
* @summary Retrieves one or more change models based on the specified criteria.
|
|
11924
|
+
*
|
|
11925
|
+
* @param {object} [sysparmQueryKeyValuePairs] - e.g. { number: 'CHG12345' }
|
|
11926
|
+
* @param {string} [sysparmQueryString] - e.g. number=CHG12345
|
|
11927
|
+
* @param {string} [order] - Field by which to sort the returned change models.
|
|
11928
|
+
* @param {number} [sysparmOffset] - Starting record index for which to begin retrieving records. Use this value to paginate record retrieval. This functionality enables the retrieval of all records, regardl...(description truncated)
|
|
11929
|
+
* @param {string} [textSearch] - String to use to search all change model record fields. This search uses ServiceNow full text search platform functionality.
|
|
11930
|
+
* @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
|
|
11931
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
11932
|
+
* @return {object} results - An object containing the response of the action
|
|
11933
|
+
*
|
|
11934
|
+
* @route {POST} /getChangeModel
|
|
11935
|
+
* @roles admin
|
|
11936
|
+
* @task true
|
|
11937
|
+
*/
|
|
11938
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
11939
|
+
getChangeModel(sysparmQueryKeyValuePairs, sysparmQueryString, order, sysparmOffset, textSearch, iapMetadata, callback) {
|
|
11940
|
+
const meth = 'adapter-getChangeModel';
|
|
11941
|
+
const origin = `${this.id}-${meth}`;
|
|
11942
|
+
log.trace(origin);
|
|
11943
|
+
|
|
11944
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
11945
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
11946
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11947
|
+
return callback(null, errorObj);
|
|
11948
|
+
}
|
|
11949
|
+
|
|
11950
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
11951
|
+
|
|
11952
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
11953
|
+
const queryParamsAvailable = { ...sysparmQueryKeyValuePairs, order, sysparmOffset, textSearch };
|
|
11954
|
+
const queryParams = {};
|
|
11955
|
+
const pathVars = [];
|
|
11956
|
+
const bodyVars = {};
|
|
11957
|
+
|
|
11958
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
11959
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
11960
|
+
if (thisKeyInQueryParamsAvailable !== 'sysparmQuery' && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined
|
|
11961
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
11962
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
11963
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
11964
|
+
}
|
|
11965
|
+
});
|
|
11966
|
+
|
|
11967
|
+
if (sysparmQueryString !== undefined && sysparmQueryString !== null && sysparmQueryString !== '') {
|
|
11968
|
+
queryParams.sysparmQuery = sysparmQueryString;
|
|
11969
|
+
} else if (sysparmQueryKeyValuePairs !== undefined && sysparmQueryKeyValuePairs !== null
|
|
11970
|
+
&& sysparmQueryKeyValuePairs.sysparmQuery !== undefined && sysparmQueryKeyValuePairs.sysparmQuery !== null
|
|
11971
|
+
&& sysparmQueryKeyValuePairs.sysparmQuery !== '') {
|
|
11972
|
+
queryParams.sysparmQuery = sysparmQueryKeyValuePairs.sysparmQuery;
|
|
11973
|
+
}
|
|
11974
|
+
|
|
11975
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
11976
|
+
// see adapter code documentation for more information on the request object's fields
|
|
11977
|
+
const reqObj = {
|
|
11978
|
+
payload: bodyVars,
|
|
11979
|
+
uriPathVars: pathVars,
|
|
11980
|
+
uriQuery: queryParams
|
|
11981
|
+
};
|
|
11982
|
+
|
|
11983
|
+
const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
|
|
11984
|
+
|
|
11985
|
+
// Merge and add new iapMetadata fields in reqObj
|
|
11986
|
+
if (iapMetadata && typeof iapMetadata === 'object') {
|
|
11987
|
+
Object.keys(iapMetadata).forEach((iapField) => {
|
|
11988
|
+
if (reqFields.includes(iapField) && iapMetadata[iapField]) {
|
|
11989
|
+
if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
|
|
11990
|
+
reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
|
|
11991
|
+
} else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
|
|
11992
|
+
reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
|
|
11993
|
+
} else {
|
|
11994
|
+
// Otherwise, add new iapMetadata fields to reqObj
|
|
11995
|
+
reqObj[iapField] = iapMetadata[iapField];
|
|
11996
|
+
}
|
|
11997
|
+
}
|
|
11998
|
+
});
|
|
11999
|
+
// Add iapMetadata to reqObj for further work
|
|
12000
|
+
reqObj.iapMetadata = iapMetadata;
|
|
12001
|
+
}
|
|
12002
|
+
|
|
12003
|
+
try {
|
|
12004
|
+
// Make the call -
|
|
12005
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
12006
|
+
return this.requestHandlerInst.identifyRequest('ChangeManagement', 'getChangeModel', reqObj, true, (irReturnData, irReturnError) => {
|
|
12007
|
+
// if we received an error or their is no response on the results
|
|
12008
|
+
// return an error
|
|
12009
|
+
if (irReturnError) {
|
|
12010
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
12011
|
+
return callback(null, irReturnError);
|
|
12012
|
+
}
|
|
12013
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
12014
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getChangeModel'], null, null, null);
|
|
12015
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12016
|
+
return callback(null, errorObj);
|
|
12017
|
+
}
|
|
12018
|
+
|
|
12019
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
12020
|
+
// return the response
|
|
12021
|
+
return callback(irReturnData, null);
|
|
12022
|
+
});
|
|
12023
|
+
} catch (ex) {
|
|
12024
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
12025
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12026
|
+
return callback(null, errorObj);
|
|
12027
|
+
}
|
|
12028
|
+
}
|
|
12029
|
+
|
|
12030
|
+
/**
|
|
12031
|
+
* @function getChangeModelById
|
|
12032
|
+
* @pronghornType method
|
|
12033
|
+
* @name getChangeModelById
|
|
12034
|
+
* @summary Retrieves the change model identified by the specified sys_id.
|
|
12035
|
+
*
|
|
12036
|
+
* @param {string} sysId - Sys_id of the change model record to retrieve from the Change Model [chg_model] table.
|
|
12037
|
+
* @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
|
|
12038
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
12039
|
+
* @return {object} results - An object containing the response of the action
|
|
12040
|
+
*
|
|
12041
|
+
* @route {POST} /getChangeModelById
|
|
12042
|
+
* @roles admin
|
|
12043
|
+
* @task true
|
|
12044
|
+
*/
|
|
12045
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
12046
|
+
getChangeModelById(sysId, iapMetadata, callback) {
|
|
12047
|
+
const meth = 'adapter-getChangeModelById';
|
|
12048
|
+
const origin = `${this.id}-${meth}`;
|
|
12049
|
+
log.trace(origin);
|
|
12050
|
+
|
|
12051
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
12052
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
12053
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12054
|
+
return callback(null, errorObj);
|
|
12055
|
+
}
|
|
12056
|
+
|
|
12057
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
12058
|
+
if (sysId === undefined || sysId === null || sysId === '') {
|
|
12059
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['sysId'], null, null, null);
|
|
12060
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12061
|
+
return callback(null, errorObj);
|
|
12062
|
+
}
|
|
12063
|
+
|
|
12064
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
12065
|
+
const queryParamsAvailable = {};
|
|
12066
|
+
const queryParams = {};
|
|
12067
|
+
const pathVars = [sysId];
|
|
12068
|
+
const bodyVars = {};
|
|
12069
|
+
|
|
12070
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
12071
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
12072
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
12073
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
12074
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
12075
|
+
}
|
|
12076
|
+
});
|
|
12077
|
+
|
|
12078
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
12079
|
+
// see adapter code documentation for more information on the request object's fields
|
|
12080
|
+
const reqObj = {
|
|
12081
|
+
payload: bodyVars,
|
|
12082
|
+
uriPathVars: pathVars,
|
|
12083
|
+
uriQuery: queryParams
|
|
12084
|
+
};
|
|
12085
|
+
|
|
12086
|
+
const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
|
|
12087
|
+
|
|
12088
|
+
// Merge and add new iapMetadata fields in reqObj
|
|
12089
|
+
if (iapMetadata && typeof iapMetadata === 'object') {
|
|
12090
|
+
Object.keys(iapMetadata).forEach((iapField) => {
|
|
12091
|
+
if (reqFields.includes(iapField) && iapMetadata[iapField]) {
|
|
12092
|
+
if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
|
|
12093
|
+
reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
|
|
12094
|
+
} else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
|
|
12095
|
+
reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
|
|
12096
|
+
} else {
|
|
12097
|
+
// Otherwise, add new iapMetadata fields to reqObj
|
|
12098
|
+
reqObj[iapField] = iapMetadata[iapField];
|
|
12099
|
+
}
|
|
12100
|
+
}
|
|
12101
|
+
});
|
|
12102
|
+
// Add iapMetadata to reqObj for further work
|
|
12103
|
+
reqObj.iapMetadata = iapMetadata;
|
|
12104
|
+
}
|
|
12105
|
+
|
|
12106
|
+
try {
|
|
12107
|
+
// Make the call -
|
|
12108
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
12109
|
+
return this.requestHandlerInst.identifyRequest('ChangeManagement', 'getChangeModelById', reqObj, true, (irReturnData, irReturnError) => {
|
|
12110
|
+
// if we received an error or their is no response on the results
|
|
12111
|
+
// return an error
|
|
12112
|
+
if (irReturnError) {
|
|
12113
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
12114
|
+
return callback(null, irReturnError);
|
|
12115
|
+
}
|
|
12116
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
12117
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getChangeModelById'], null, null, null);
|
|
12118
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12119
|
+
return callback(null, errorObj);
|
|
12120
|
+
}
|
|
12121
|
+
|
|
12122
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
12123
|
+
// return the response
|
|
12124
|
+
return callback(irReturnData, null);
|
|
12125
|
+
});
|
|
12126
|
+
} catch (ex) {
|
|
12127
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
12128
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12129
|
+
return callback(null, errorObj);
|
|
12130
|
+
}
|
|
12131
|
+
}
|
|
12132
|
+
|
|
12133
|
+
/**
|
|
12134
|
+
* @function getChangeWorkerById
|
|
12135
|
+
* @pronghornType method
|
|
12136
|
+
* @name getChangeWorkerById
|
|
12137
|
+
* @summary Retrieves the current status, information, and errors for the specified asynchronous worker.
|
|
12138
|
+
*
|
|
12139
|
+
* @param {string} sysId - Sys_id of the change management asynchronous worker. Located in the Change Management Worker [chg_mgt_worker] table.
|
|
12140
|
+
* @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
|
|
12141
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
12142
|
+
* @return {object} results - An object containing the response of the action
|
|
12143
|
+
*
|
|
12144
|
+
* @route {POST} /getChangeWorkerById
|
|
12145
|
+
* @roles admin
|
|
12146
|
+
* @task true
|
|
12147
|
+
*/
|
|
12148
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
12149
|
+
getChangeWorkerById(sysId, iapMetadata, callback) {
|
|
12150
|
+
const meth = 'adapter-getChangeWorkerById';
|
|
12151
|
+
const origin = `${this.id}-${meth}`;
|
|
12152
|
+
log.trace(origin);
|
|
12153
|
+
|
|
12154
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
12155
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
12156
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12157
|
+
return callback(null, errorObj);
|
|
12158
|
+
}
|
|
12159
|
+
|
|
12160
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
12161
|
+
if (sysId === undefined || sysId === null || sysId === '') {
|
|
12162
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['sysId'], null, null, null);
|
|
12163
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12164
|
+
return callback(null, errorObj);
|
|
12165
|
+
}
|
|
12166
|
+
|
|
12167
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
12168
|
+
const queryParamsAvailable = {};
|
|
12169
|
+
const queryParams = {};
|
|
12170
|
+
const pathVars = [sysId];
|
|
12171
|
+
const bodyVars = {};
|
|
12172
|
+
|
|
12173
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
12174
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
12175
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
12176
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
12177
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
12178
|
+
}
|
|
12179
|
+
});
|
|
12180
|
+
|
|
12181
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
12182
|
+
// see adapter code documentation for more information on the request object's fields
|
|
12183
|
+
const reqObj = {
|
|
12184
|
+
payload: bodyVars,
|
|
12185
|
+
uriPathVars: pathVars,
|
|
12186
|
+
uriQuery: queryParams
|
|
12187
|
+
};
|
|
12188
|
+
|
|
12189
|
+
const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
|
|
12190
|
+
|
|
12191
|
+
// Merge and add new iapMetadata fields in reqObj
|
|
12192
|
+
if (iapMetadata && typeof iapMetadata === 'object') {
|
|
12193
|
+
Object.keys(iapMetadata).forEach((iapField) => {
|
|
12194
|
+
if (reqFields.includes(iapField) && iapMetadata[iapField]) {
|
|
12195
|
+
if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
|
|
12196
|
+
reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
|
|
12197
|
+
} else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
|
|
12198
|
+
reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
|
|
12199
|
+
} else {
|
|
12200
|
+
// Otherwise, add new iapMetadata fields to reqObj
|
|
12201
|
+
reqObj[iapField] = iapMetadata[iapField];
|
|
12202
|
+
}
|
|
12203
|
+
}
|
|
12204
|
+
});
|
|
12205
|
+
// Add iapMetadata to reqObj for further work
|
|
12206
|
+
reqObj.iapMetadata = iapMetadata;
|
|
12207
|
+
}
|
|
12208
|
+
|
|
12209
|
+
try {
|
|
12210
|
+
// Make the call -
|
|
12211
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
12212
|
+
return this.requestHandlerInst.identifyRequest('ChangeManagement', 'getChangeWorkerById', reqObj, true, (irReturnData, irReturnError) => {
|
|
12213
|
+
// if we received an error or their is no response on the results
|
|
12214
|
+
// return an error
|
|
12215
|
+
if (irReturnError) {
|
|
12216
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
12217
|
+
return callback(null, irReturnError);
|
|
12218
|
+
}
|
|
12219
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
12220
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getChangeWorkerById'], null, null, null);
|
|
12221
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12222
|
+
return callback(null, errorObj);
|
|
12223
|
+
}
|
|
12224
|
+
|
|
12225
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
12226
|
+
// return the response
|
|
12227
|
+
return callback(irReturnData, null);
|
|
12228
|
+
});
|
|
12229
|
+
} catch (ex) {
|
|
12230
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
12231
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12232
|
+
return callback(null, errorObj);
|
|
12233
|
+
}
|
|
12234
|
+
}
|
|
12235
|
+
|
|
12236
|
+
/**
|
|
12237
|
+
* @function updateChangeRequestById
|
|
12238
|
+
* @pronghornType method
|
|
12239
|
+
* @name updateChangeRequestById
|
|
12240
|
+
* @summary Updates the change request identified by the specified sys_id with the key-value pairs in the reque
|
|
12241
|
+
*
|
|
12242
|
+
* @param {string} sysId - Sys_id of the change request to modify. Located in the Change Request [change_request] table.
|
|
12243
|
+
* @param {object} [sysparmQueryKeyValuePairs] - e.g. { number: 'CHG12345' }
|
|
12244
|
+
* @param {string} [sysparmQueryString] - e.g. number=CHG12345
|
|
12245
|
+
* @param {string} [encryptedFields] - List of comma-separated fields to encrypt. These fields are encrypted before they are stored in the associated record. When specified, the endpoint calls the GlideRecord ...(description truncated)
|
|
12246
|
+
* @param {object} body - body param
|
|
12247
|
+
* @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
|
|
12248
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
12249
|
+
* @return {object} results - An object containing the response of the action
|
|
12250
|
+
*
|
|
12251
|
+
* @route {POST} /updateChangeRequestById
|
|
12252
|
+
* @roles admin
|
|
12253
|
+
* @task true
|
|
12254
|
+
*/
|
|
12255
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
12256
|
+
updateChangeRequestById(sysId, sysparmQueryKeyValuePairs, sysparmQueryString, encryptedFields, body, iapMetadata, callback) {
|
|
12257
|
+
const meth = 'adapter-updateChangeRequestById';
|
|
12258
|
+
const origin = `${this.id}-${meth}`;
|
|
12259
|
+
log.trace(origin);
|
|
12260
|
+
|
|
12261
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
12262
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
12263
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12264
|
+
return callback(null, errorObj);
|
|
12265
|
+
}
|
|
12266
|
+
|
|
12267
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
12268
|
+
if (sysId === undefined || sysId === null || sysId === '') {
|
|
12269
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['sysId'], null, null, null);
|
|
12270
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12271
|
+
return callback(null, errorObj);
|
|
12272
|
+
}
|
|
12273
|
+
if (body === undefined || body === null || body === '') {
|
|
12274
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
|
|
12275
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12276
|
+
return callback(null, errorObj);
|
|
12277
|
+
}
|
|
12278
|
+
|
|
12279
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
12280
|
+
const queryParamsAvailable = { ...sysparmQueryKeyValuePairs, encryptedFields };
|
|
12281
|
+
const queryParams = {};
|
|
12282
|
+
const pathVars = [sysId];
|
|
12283
|
+
const bodyVars = body;
|
|
12284
|
+
|
|
12285
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
12286
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
12287
|
+
if (thisKeyInQueryParamsAvailable !== 'sysparmQuery' && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined
|
|
12288
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
12289
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
12290
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
12291
|
+
}
|
|
12292
|
+
});
|
|
12293
|
+
|
|
12294
|
+
if (sysparmQueryString !== undefined && sysparmQueryString !== null && sysparmQueryString !== '') {
|
|
12295
|
+
queryParams.sysparmQuery = sysparmQueryString;
|
|
12296
|
+
} else if (sysparmQueryKeyValuePairs !== undefined && sysparmQueryKeyValuePairs !== null
|
|
12297
|
+
&& sysparmQueryKeyValuePairs.sysparmQuery !== undefined && sysparmQueryKeyValuePairs.sysparmQuery !== null
|
|
12298
|
+
&& sysparmQueryKeyValuePairs.sysparmQuery !== '') {
|
|
12299
|
+
queryParams.sysparmQuery = sysparmQueryKeyValuePairs.sysparmQuery;
|
|
12300
|
+
}
|
|
12301
|
+
|
|
12302
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
12303
|
+
// see adapter code documentation for more information on the request object's fields
|
|
12304
|
+
const reqObj = {
|
|
12305
|
+
payload: bodyVars,
|
|
12306
|
+
uriPathVars: pathVars,
|
|
12307
|
+
uriQuery: queryParams
|
|
12308
|
+
};
|
|
12309
|
+
|
|
12310
|
+
const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
|
|
12311
|
+
|
|
12312
|
+
// Merge and add new iapMetadata fields in reqObj
|
|
12313
|
+
if (iapMetadata && typeof iapMetadata === 'object') {
|
|
12314
|
+
Object.keys(iapMetadata).forEach((iapField) => {
|
|
12315
|
+
if (reqFields.includes(iapField) && iapMetadata[iapField]) {
|
|
12316
|
+
if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
|
|
12317
|
+
reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
|
|
12318
|
+
} else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
|
|
12319
|
+
reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
|
|
12320
|
+
} else {
|
|
12321
|
+
// Otherwise, add new iapMetadata fields to reqObj
|
|
12322
|
+
reqObj[iapField] = iapMetadata[iapField];
|
|
12323
|
+
}
|
|
12324
|
+
}
|
|
12325
|
+
});
|
|
12326
|
+
// Add iapMetadata to reqObj for further work
|
|
12327
|
+
reqObj.iapMetadata = iapMetadata;
|
|
12328
|
+
}
|
|
12329
|
+
|
|
12330
|
+
try {
|
|
12331
|
+
// Make the call -
|
|
12332
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
12333
|
+
return this.requestHandlerInst.identifyRequest('ChangeManagement', 'updateChangeRequestById', reqObj, true, (irReturnData, irReturnError) => {
|
|
12334
|
+
// if we received an error or their is no response on the results
|
|
12335
|
+
// return an error
|
|
12336
|
+
if (irReturnError) {
|
|
12337
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
12338
|
+
return callback(null, irReturnError);
|
|
12339
|
+
}
|
|
12340
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
12341
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['updateChangeRequestById'], null, null, null);
|
|
12342
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12343
|
+
return callback(null, errorObj);
|
|
12344
|
+
}
|
|
12345
|
+
|
|
12346
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
12347
|
+
// return the response
|
|
12348
|
+
return callback(irReturnData, null);
|
|
12349
|
+
});
|
|
12350
|
+
} catch (ex) {
|
|
12351
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
12352
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12353
|
+
return callback(null, errorObj);
|
|
12354
|
+
}
|
|
12355
|
+
}
|
|
12356
|
+
|
|
12357
|
+
/**
|
|
12358
|
+
* @function deleteChangeRequestById
|
|
12359
|
+
* @pronghornType method
|
|
12360
|
+
* @name deleteChangeRequestById
|
|
12361
|
+
* @summary Deletes the change request associated with the specified sys_id.
|
|
12362
|
+
*
|
|
12363
|
+
* @param {string} sysId - Sys_id of the change request record to delete. Located in the Change Request [change_request] table.
|
|
12364
|
+
* @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
|
|
12365
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
12366
|
+
* @return {object} results - An object containing the response of the action
|
|
12367
|
+
*
|
|
12368
|
+
* @route {POST} /deleteChangeRequestById
|
|
12369
|
+
* @roles admin
|
|
12370
|
+
* @task true
|
|
12371
|
+
*/
|
|
12372
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
12373
|
+
deleteChangeRequestById(sysId, iapMetadata, callback) {
|
|
12374
|
+
const meth = 'adapter-deleteChangeRequestById';
|
|
12375
|
+
const origin = `${this.id}-${meth}`;
|
|
12376
|
+
log.trace(origin);
|
|
12377
|
+
|
|
12378
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
12379
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
12380
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12381
|
+
return callback(null, errorObj);
|
|
12382
|
+
}
|
|
12383
|
+
|
|
12384
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
12385
|
+
if (sysId === undefined || sysId === null || sysId === '') {
|
|
12386
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['sysId'], null, null, null);
|
|
12387
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12388
|
+
return callback(null, errorObj);
|
|
12389
|
+
}
|
|
12390
|
+
|
|
12391
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
12392
|
+
const queryParamsAvailable = {};
|
|
12393
|
+
const queryParams = {};
|
|
12394
|
+
const pathVars = [sysId];
|
|
12395
|
+
const bodyVars = {};
|
|
12396
|
+
|
|
12397
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
12398
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
12399
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
12400
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
12401
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
12402
|
+
}
|
|
12403
|
+
});
|
|
12404
|
+
|
|
12405
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
12406
|
+
// see adapter code documentation for more information on the request object's fields
|
|
12407
|
+
const reqObj = {
|
|
12408
|
+
payload: bodyVars,
|
|
12409
|
+
uriPathVars: pathVars,
|
|
12410
|
+
uriQuery: queryParams
|
|
12411
|
+
};
|
|
12412
|
+
|
|
12413
|
+
const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
|
|
12414
|
+
|
|
12415
|
+
// Merge and add new iapMetadata fields in reqObj
|
|
12416
|
+
if (iapMetadata && typeof iapMetadata === 'object') {
|
|
12417
|
+
Object.keys(iapMetadata).forEach((iapField) => {
|
|
12418
|
+
if (reqFields.includes(iapField) && iapMetadata[iapField]) {
|
|
12419
|
+
if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
|
|
12420
|
+
reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
|
|
12421
|
+
} else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
|
|
12422
|
+
reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
|
|
12423
|
+
} else {
|
|
12424
|
+
// Otherwise, add new iapMetadata fields to reqObj
|
|
12425
|
+
reqObj[iapField] = iapMetadata[iapField];
|
|
12426
|
+
}
|
|
12427
|
+
}
|
|
12428
|
+
});
|
|
12429
|
+
// Add iapMetadata to reqObj for further work
|
|
12430
|
+
reqObj.iapMetadata = iapMetadata;
|
|
12431
|
+
}
|
|
12432
|
+
|
|
12433
|
+
try {
|
|
12434
|
+
// Make the call -
|
|
12435
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
12436
|
+
return this.requestHandlerInst.identifyRequest('ChangeManagement', 'deleteChangeRequestById', reqObj, false, (irReturnData, irReturnError) => {
|
|
12437
|
+
// if we received an error or their is no response on the results
|
|
12438
|
+
// return an error
|
|
12439
|
+
if (irReturnError) {
|
|
12440
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
12441
|
+
return callback(null, irReturnError);
|
|
12442
|
+
}
|
|
12443
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
12444
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['deleteChangeRequestById'], null, null, null);
|
|
12445
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12446
|
+
return callback(null, errorObj);
|
|
12447
|
+
}
|
|
12448
|
+
|
|
12449
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
12450
|
+
// return the response
|
|
12451
|
+
return callback(irReturnData, null);
|
|
12452
|
+
});
|
|
12453
|
+
} catch (ex) {
|
|
12454
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
12455
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12456
|
+
return callback(null, errorObj);
|
|
12457
|
+
}
|
|
12458
|
+
}
|
|
12459
|
+
|
|
12460
|
+
/**
|
|
12461
|
+
* @function getChangeRequestRecordById
|
|
12462
|
+
* @pronghornType method
|
|
12463
|
+
* @name getChangeRequestRecordById
|
|
12464
|
+
* @summary Retrieves the change request identified by the specified sys_id.
|
|
12465
|
+
*
|
|
12466
|
+
* @param {string} sysId - Sys_id of the change request record to retrieve from Change Request [change_request] table.
|
|
12467
|
+
* @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
|
|
12468
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
12469
|
+
* @return {object} results - An object containing the response of the action
|
|
12470
|
+
*
|
|
12471
|
+
* @route {POST} /getChangeRequestRecordById
|
|
12472
|
+
* @roles admin
|
|
12473
|
+
* @task true
|
|
12474
|
+
*/
|
|
12475
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
12476
|
+
getChangeRequestRecordById(sysId, iapMetadata, callback) {
|
|
12477
|
+
const meth = 'adapter-getChangeRequestRecordById';
|
|
12478
|
+
const origin = `${this.id}-${meth}`;
|
|
12479
|
+
log.trace(origin);
|
|
12480
|
+
|
|
12481
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
12482
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
12483
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12484
|
+
return callback(null, errorObj);
|
|
12485
|
+
}
|
|
12486
|
+
|
|
12487
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
12488
|
+
if (sysId === undefined || sysId === null || sysId === '') {
|
|
12489
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['sysId'], null, null, null);
|
|
12490
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12491
|
+
return callback(null, errorObj);
|
|
12492
|
+
}
|
|
12493
|
+
|
|
12494
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
12495
|
+
const queryParamsAvailable = {};
|
|
12496
|
+
const queryParams = {};
|
|
12497
|
+
const pathVars = [sysId];
|
|
12498
|
+
const bodyVars = {};
|
|
12499
|
+
|
|
12500
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
12501
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
12502
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
12503
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
12504
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
12505
|
+
}
|
|
12506
|
+
});
|
|
12507
|
+
|
|
12508
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
12509
|
+
// see adapter code documentation for more information on the request object's fields
|
|
12510
|
+
const reqObj = {
|
|
12511
|
+
payload: bodyVars,
|
|
12512
|
+
uriPathVars: pathVars,
|
|
12513
|
+
uriQuery: queryParams
|
|
12514
|
+
};
|
|
12515
|
+
|
|
12516
|
+
const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
|
|
12517
|
+
|
|
12518
|
+
// Merge and add new iapMetadata fields in reqObj
|
|
12519
|
+
if (iapMetadata && typeof iapMetadata === 'object') {
|
|
12520
|
+
Object.keys(iapMetadata).forEach((iapField) => {
|
|
12521
|
+
if (reqFields.includes(iapField) && iapMetadata[iapField]) {
|
|
12522
|
+
if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
|
|
12523
|
+
reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
|
|
12524
|
+
} else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
|
|
12525
|
+
reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
|
|
12526
|
+
} else {
|
|
12527
|
+
// Otherwise, add new iapMetadata fields to reqObj
|
|
12528
|
+
reqObj[iapField] = iapMetadata[iapField];
|
|
12529
|
+
}
|
|
12530
|
+
}
|
|
12531
|
+
});
|
|
12532
|
+
// Add iapMetadata to reqObj for further work
|
|
12533
|
+
reqObj.iapMetadata = iapMetadata;
|
|
12534
|
+
}
|
|
12535
|
+
|
|
12536
|
+
try {
|
|
12537
|
+
// Make the call -
|
|
12538
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
12539
|
+
return this.requestHandlerInst.identifyRequest('ChangeManagement', 'getChangeRequestRecordById', reqObj, true, (irReturnData, irReturnError) => {
|
|
12540
|
+
// if we received an error or their is no response on the results
|
|
12541
|
+
// return an error
|
|
12542
|
+
if (irReturnError) {
|
|
12543
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
12544
|
+
return callback(null, irReturnError);
|
|
12545
|
+
}
|
|
12546
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
12547
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getChangeRequestRecordById'], null, null, null);
|
|
12548
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12549
|
+
return callback(null, errorObj);
|
|
12550
|
+
}
|
|
12551
|
+
|
|
12552
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
12553
|
+
// return the response
|
|
12554
|
+
return callback(irReturnData, null);
|
|
12555
|
+
});
|
|
12556
|
+
} catch (ex) {
|
|
12557
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
12558
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12559
|
+
return callback(null, errorObj);
|
|
12560
|
+
}
|
|
12561
|
+
}
|
|
12562
|
+
|
|
12563
|
+
/**
|
|
12564
|
+
* @function addChangeRequestConfigurationItem
|
|
12565
|
+
* @pronghornType method
|
|
12566
|
+
* @name addChangeRequestConfigurationItem
|
|
12567
|
+
* @summary Creates the association between a change request and Configuration Management Database (CMDB) confi
|
|
12568
|
+
*
|
|
12569
|
+
* @param {string} changeSysId - Change_Sys_id of the change request to associate with the CMDB CI.
|
|
12570
|
+
* @param {object} body - body param
|
|
12571
|
+
* @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
|
|
12572
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
12573
|
+
* @return {object} results - An object containing the response of the action
|
|
12574
|
+
*
|
|
12575
|
+
* @route {POST} /addChangeRequestConfigurationItem
|
|
12576
|
+
* @roles admin
|
|
12577
|
+
* @task true
|
|
12578
|
+
*/
|
|
12579
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
12580
|
+
addChangeRequestConfigurationItem(changeSysId, body, iapMetadata, callback) {
|
|
12581
|
+
const meth = 'adapter-addChangeRequestConfigurationItem';
|
|
12582
|
+
const origin = `${this.id}-${meth}`;
|
|
12583
|
+
log.trace(origin);
|
|
12584
|
+
|
|
12585
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
12586
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
12587
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12588
|
+
return callback(null, errorObj);
|
|
12589
|
+
}
|
|
12590
|
+
|
|
12591
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
12592
|
+
if (changeSysId === undefined || changeSysId === null || changeSysId === '') {
|
|
12593
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['changeSysId'], null, null, null);
|
|
12594
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12595
|
+
return callback(null, errorObj);
|
|
12596
|
+
}
|
|
12597
|
+
if (body === undefined || body === null || body === '') {
|
|
12598
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
|
|
12599
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12600
|
+
return callback(null, errorObj);
|
|
12601
|
+
}
|
|
12602
|
+
|
|
12603
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
12604
|
+
const queryParamsAvailable = {};
|
|
12605
|
+
const queryParams = {};
|
|
12606
|
+
const pathVars = [changeSysId];
|
|
12607
|
+
const bodyVars = body;
|
|
12608
|
+
|
|
12609
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
12610
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
12611
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
12612
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
12613
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
12614
|
+
}
|
|
12615
|
+
});
|
|
12616
|
+
|
|
12617
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
12618
|
+
// see adapter code documentation for more information on the request object's fields
|
|
12619
|
+
const reqObj = {
|
|
12620
|
+
payload: bodyVars,
|
|
12621
|
+
uriPathVars: pathVars,
|
|
12622
|
+
uriQuery: queryParams
|
|
12623
|
+
};
|
|
12624
|
+
|
|
12625
|
+
const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
|
|
12626
|
+
|
|
12627
|
+
// Merge and add new iapMetadata fields in reqObj
|
|
12628
|
+
if (iapMetadata && typeof iapMetadata === 'object') {
|
|
12629
|
+
Object.keys(iapMetadata).forEach((iapField) => {
|
|
12630
|
+
if (reqFields.includes(iapField) && iapMetadata[iapField]) {
|
|
12631
|
+
if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
|
|
12632
|
+
reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
|
|
12633
|
+
} else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
|
|
12634
|
+
reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
|
|
12635
|
+
} else {
|
|
12636
|
+
// Otherwise, add new iapMetadata fields to reqObj
|
|
12637
|
+
reqObj[iapField] = iapMetadata[iapField];
|
|
12638
|
+
}
|
|
12639
|
+
}
|
|
12640
|
+
});
|
|
12641
|
+
// Add iapMetadata to reqObj for further work
|
|
12642
|
+
reqObj.iapMetadata = iapMetadata;
|
|
12643
|
+
}
|
|
12644
|
+
|
|
12645
|
+
try {
|
|
12646
|
+
// Make the call -
|
|
12647
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
12648
|
+
return this.requestHandlerInst.identifyRequest('ChangeManagement', 'addChangeRequestConfigurationItem', reqObj, true, (irReturnData, irReturnError) => {
|
|
12649
|
+
// if we received an error or their is no response on the results
|
|
12650
|
+
// return an error
|
|
12651
|
+
if (irReturnError) {
|
|
12652
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
12653
|
+
return callback(null, irReturnError);
|
|
12654
|
+
}
|
|
12655
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
12656
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['addChangeRequestConfigurationItem'], null, null, null);
|
|
12657
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12658
|
+
return callback(null, errorObj);
|
|
12659
|
+
}
|
|
12660
|
+
|
|
12661
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
12662
|
+
// return the response
|
|
12663
|
+
return callback(irReturnData, null);
|
|
12664
|
+
});
|
|
12665
|
+
} catch (ex) {
|
|
12666
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
12667
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12668
|
+
return callback(null, errorObj);
|
|
12669
|
+
}
|
|
12670
|
+
}
|
|
12671
|
+
|
|
12672
|
+
/**
|
|
12673
|
+
* @function getChangeRequestConfigurationItems
|
|
12674
|
+
* @pronghornType method
|
|
12675
|
+
* @name getChangeRequestConfigurationItems
|
|
12676
|
+
* @summary Retrieves multiple configuration items (CIs) associated to a specified change request based on the
|
|
12677
|
+
*
|
|
12678
|
+
* @param {string} changeSysId - Sys_id of the change request for which to return the associated CMDB CIs.
|
|
12679
|
+
* @param {string} [associationType] - Type of association between the CMDB CI and the change request.
|
|
12680
|
+
* @param {object} [sysparmQueryKeyValuePairs] - e.g. { number: 'CHG12345' }
|
|
12681
|
+
* @param {string} [sysparmQueryString] - e.g. number=CHG12345
|
|
12682
|
+
* @param {number} [sysparmLimit] - Maximum number of records to return. For requests that exceed this number of records, use the sysparm_offset parameter to paginate record retrieval.
|
|
12683
|
+
* @param {number} [sysparmOffset] - Starting record index for which to begin retrieving records. Use this value to paginate record retrieval. This functionality enables the retrieval of all records, regardl...(description truncated)
|
|
12684
|
+
* @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
|
|
12685
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
12686
|
+
* @return {object} results - An object containing the response of the action
|
|
12687
|
+
*
|
|
12688
|
+
* @route {POST} /getChangeRequestConfigurationItems
|
|
12689
|
+
* @roles admin
|
|
12690
|
+
* @task true
|
|
12691
|
+
*/
|
|
12692
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
12693
|
+
getChangeRequestConfigurationItems(changeSysId, associationType, sysparmQueryKeyValuePairs, sysparmQueryString, sysparmLimit, sysparmOffset, iapMetadata, callback) {
|
|
12694
|
+
const meth = 'adapter-getChangeRequestConfigurationItems';
|
|
12695
|
+
const origin = `${this.id}-${meth}`;
|
|
12696
|
+
log.trace(origin);
|
|
12697
|
+
|
|
12698
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
12699
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
12700
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12701
|
+
return callback(null, errorObj);
|
|
12702
|
+
}
|
|
12703
|
+
|
|
12704
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
12705
|
+
if (changeSysId === undefined || changeSysId === null || changeSysId === '') {
|
|
12706
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['changeSysId'], null, null, null);
|
|
12707
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12708
|
+
return callback(null, errorObj);
|
|
12709
|
+
}
|
|
12710
|
+
|
|
12711
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
12712
|
+
const queryParamsAvailable = { associationType, ...sysparmQueryKeyValuePairs, sysparmLimit, sysparmOffset };
|
|
12713
|
+
const queryParams = {};
|
|
12714
|
+
const pathVars = [changeSysId];
|
|
12715
|
+
const bodyVars = {};
|
|
12716
|
+
|
|
12717
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
12718
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
12719
|
+
if (thisKeyInQueryParamsAvailable !== 'sysparmQuery' && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined
|
|
12720
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
12721
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
12722
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
12723
|
+
}
|
|
12724
|
+
});
|
|
12725
|
+
|
|
12726
|
+
if (sysparmQueryString !== undefined && sysparmQueryString !== null && sysparmQueryString !== '') {
|
|
12727
|
+
queryParams.sysparmQuery = sysparmQueryString;
|
|
12728
|
+
} else if (sysparmQueryKeyValuePairs !== undefined && sysparmQueryKeyValuePairs !== null
|
|
12729
|
+
&& sysparmQueryKeyValuePairs.sysparmQuery !== undefined && sysparmQueryKeyValuePairs.sysparmQuery !== null
|
|
12730
|
+
&& sysparmQueryKeyValuePairs.sysparmQuery !== '') {
|
|
12731
|
+
queryParams.sysparmQuery = sysparmQueryKeyValuePairs.sysparmQuery;
|
|
12732
|
+
}
|
|
12733
|
+
|
|
12734
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
12735
|
+
// see adapter code documentation for more information on the request object's fields
|
|
12736
|
+
const reqObj = {
|
|
12737
|
+
payload: bodyVars,
|
|
12738
|
+
uriPathVars: pathVars,
|
|
12739
|
+
uriQuery: queryParams
|
|
12740
|
+
};
|
|
12741
|
+
|
|
12742
|
+
const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
|
|
12743
|
+
|
|
12744
|
+
// Merge and add new iapMetadata fields in reqObj
|
|
12745
|
+
if (iapMetadata && typeof iapMetadata === 'object') {
|
|
12746
|
+
Object.keys(iapMetadata).forEach((iapField) => {
|
|
12747
|
+
if (reqFields.includes(iapField) && iapMetadata[iapField]) {
|
|
12748
|
+
if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
|
|
12749
|
+
reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
|
|
12750
|
+
} else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
|
|
12751
|
+
reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
|
|
12752
|
+
} else {
|
|
12753
|
+
// Otherwise, add new iapMetadata fields to reqObj
|
|
12754
|
+
reqObj[iapField] = iapMetadata[iapField];
|
|
12755
|
+
}
|
|
12756
|
+
}
|
|
12757
|
+
});
|
|
12758
|
+
// Add iapMetadata to reqObj for further work
|
|
12759
|
+
reqObj.iapMetadata = iapMetadata;
|
|
12760
|
+
}
|
|
12761
|
+
|
|
12762
|
+
try {
|
|
12763
|
+
// Make the call -
|
|
12764
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
12765
|
+
return this.requestHandlerInst.identifyRequest('ChangeManagement', 'getChangeRequestConfigurationItems', reqObj, true, (irReturnData, irReturnError) => {
|
|
12766
|
+
// if we received an error or their is no response on the results
|
|
12767
|
+
// return an error
|
|
12768
|
+
if (irReturnError) {
|
|
12769
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
12770
|
+
return callback(null, irReturnError);
|
|
12771
|
+
}
|
|
12772
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
12773
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getChangeRequestConfigurationItems'], null, null, null);
|
|
12774
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12775
|
+
return callback(null, errorObj);
|
|
12776
|
+
}
|
|
12777
|
+
|
|
12778
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
12779
|
+
// return the response
|
|
12780
|
+
return callback(irReturnData, null);
|
|
12781
|
+
});
|
|
12782
|
+
} catch (ex) {
|
|
12783
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
12784
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12785
|
+
return callback(null, errorObj);
|
|
12786
|
+
}
|
|
12787
|
+
}
|
|
12788
|
+
|
|
12789
|
+
/**
|
|
12790
|
+
* @function getChangeRequestNextStates
|
|
12791
|
+
* @pronghornType method
|
|
12792
|
+
* @name getChangeRequestNextStates
|
|
12793
|
+
* @summary Retrieves a list of available states for the specified change request, including the current state.
|
|
12794
|
+
*
|
|
12795
|
+
* @param {string} changeSysId - Sys_id of the change request. Located in the Change Request [change_request] table.
|
|
12796
|
+
* @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
|
|
12797
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
12798
|
+
* @return {object} results - An object containing the response of the action
|
|
12799
|
+
*
|
|
12800
|
+
* @route {POST} /getChangeRequestNextStates
|
|
12801
|
+
* @roles admin
|
|
12802
|
+
* @task true
|
|
12803
|
+
*/
|
|
12804
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
12805
|
+
getChangeRequestNextStates(changeSysId, iapMetadata, callback) {
|
|
12806
|
+
const meth = 'adapter-getChangeRequestNextStates';
|
|
12807
|
+
const origin = `${this.id}-${meth}`;
|
|
12808
|
+
log.trace(origin);
|
|
12809
|
+
|
|
12810
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
12811
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
12812
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12813
|
+
return callback(null, errorObj);
|
|
12814
|
+
}
|
|
12815
|
+
|
|
12816
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
12817
|
+
if (changeSysId === undefined || changeSysId === null || changeSysId === '') {
|
|
12818
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['changeSysId'], null, null, null);
|
|
12819
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12820
|
+
return callback(null, errorObj);
|
|
12821
|
+
}
|
|
12822
|
+
|
|
12823
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
12824
|
+
const queryParamsAvailable = {};
|
|
12825
|
+
const queryParams = {};
|
|
12826
|
+
const pathVars = [changeSysId];
|
|
12827
|
+
const bodyVars = {};
|
|
12828
|
+
|
|
12829
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
12830
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
12831
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
12832
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
12833
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
12834
|
+
}
|
|
12835
|
+
});
|
|
12836
|
+
|
|
12837
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
12838
|
+
// see adapter code documentation for more information on the request object's fields
|
|
12839
|
+
const reqObj = {
|
|
12840
|
+
payload: bodyVars,
|
|
12841
|
+
uriPathVars: pathVars,
|
|
12842
|
+
uriQuery: queryParams
|
|
12843
|
+
};
|
|
12844
|
+
|
|
12845
|
+
const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
|
|
12846
|
+
|
|
12847
|
+
// Merge and add new iapMetadata fields in reqObj
|
|
12848
|
+
if (iapMetadata && typeof iapMetadata === 'object') {
|
|
12849
|
+
Object.keys(iapMetadata).forEach((iapField) => {
|
|
12850
|
+
if (reqFields.includes(iapField) && iapMetadata[iapField]) {
|
|
12851
|
+
if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
|
|
12852
|
+
reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
|
|
12853
|
+
} else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
|
|
12854
|
+
reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
|
|
12855
|
+
} else {
|
|
12856
|
+
// Otherwise, add new iapMetadata fields to reqObj
|
|
12857
|
+
reqObj[iapField] = iapMetadata[iapField];
|
|
12858
|
+
}
|
|
12859
|
+
}
|
|
12860
|
+
});
|
|
12861
|
+
// Add iapMetadata to reqObj for further work
|
|
12862
|
+
reqObj.iapMetadata = iapMetadata;
|
|
12863
|
+
}
|
|
12864
|
+
|
|
12865
|
+
try {
|
|
12866
|
+
// Make the call -
|
|
12867
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
12868
|
+
return this.requestHandlerInst.identifyRequest('ChangeManagement', 'getChangeRequestNextStates', reqObj, true, (irReturnData, irReturnError) => {
|
|
12869
|
+
// if we received an error or their is no response on the results
|
|
12870
|
+
// return an error
|
|
12871
|
+
if (irReturnError) {
|
|
12872
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
12873
|
+
return callback(null, irReturnError);
|
|
12874
|
+
}
|
|
12875
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
12876
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getChangeRequestNextStates'], null, null, null);
|
|
12877
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12878
|
+
return callback(null, errorObj);
|
|
12879
|
+
}
|
|
12880
|
+
|
|
12881
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
12882
|
+
// return the response
|
|
12883
|
+
return callback(irReturnData, null);
|
|
12884
|
+
});
|
|
12885
|
+
} catch (ex) {
|
|
12886
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
12887
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12888
|
+
return callback(null, errorObj);
|
|
12889
|
+
}
|
|
12890
|
+
}
|
|
12891
|
+
|
|
12892
|
+
/**
|
|
12893
|
+
* @function refreshChangeRequestImpactedServices
|
|
12894
|
+
* @pronghornType method
|
|
12895
|
+
* @name refreshChangeRequestImpactedServices
|
|
12896
|
+
* @summary Populates the impacted services\/configuration items (CIs) related list based on the primary CI.
|
|
12897
|
+
*
|
|
12898
|
+
* @param {string} changeSysId - Change_Sys_id of the change request to use to refresh the impacted services.
|
|
12899
|
+
* @param {object} body - body param
|
|
12900
|
+
* @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
|
|
12901
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
12902
|
+
* @return {object} results - An object containing the response of the action
|
|
12903
|
+
*
|
|
12904
|
+
* @route {POST} /refreshChangeRequestImpactedServices
|
|
12905
|
+
* @roles admin
|
|
12906
|
+
* @task true
|
|
12907
|
+
*/
|
|
12908
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
12909
|
+
refreshChangeRequestImpactedServices(changeSysId, body, iapMetadata, callback) {
|
|
12910
|
+
const meth = 'adapter-refreshChangeRequestImpactedServices';
|
|
12911
|
+
const origin = `${this.id}-${meth}`;
|
|
12912
|
+
log.trace(origin);
|
|
12913
|
+
|
|
12914
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
12915
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
12916
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12917
|
+
return callback(null, errorObj);
|
|
12918
|
+
}
|
|
12919
|
+
|
|
12920
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
12921
|
+
if (changeSysId === undefined || changeSysId === null || changeSysId === '') {
|
|
12922
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['changeSysId'], null, null, null);
|
|
12923
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12924
|
+
return callback(null, errorObj);
|
|
12925
|
+
}
|
|
12926
|
+
if (body === undefined || body === null || body === '') {
|
|
12927
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
|
|
12928
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12929
|
+
return callback(null, errorObj);
|
|
12930
|
+
}
|
|
12931
|
+
|
|
12932
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
12933
|
+
const queryParamsAvailable = {};
|
|
12934
|
+
const queryParams = {};
|
|
12935
|
+
const pathVars = [changeSysId];
|
|
12936
|
+
const bodyVars = body;
|
|
12937
|
+
|
|
12938
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
12939
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
12940
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
12941
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
12942
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
12943
|
+
}
|
|
12944
|
+
});
|
|
12945
|
+
|
|
12946
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
12947
|
+
// see adapter code documentation for more information on the request object's fields
|
|
12948
|
+
const reqObj = {
|
|
12949
|
+
payload: bodyVars,
|
|
12950
|
+
uriPathVars: pathVars,
|
|
12951
|
+
uriQuery: queryParams
|
|
12952
|
+
};
|
|
12953
|
+
|
|
12954
|
+
const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
|
|
12955
|
+
|
|
12956
|
+
// Merge and add new iapMetadata fields in reqObj
|
|
12957
|
+
if (iapMetadata && typeof iapMetadata === 'object') {
|
|
12958
|
+
Object.keys(iapMetadata).forEach((iapField) => {
|
|
12959
|
+
if (reqFields.includes(iapField) && iapMetadata[iapField]) {
|
|
12960
|
+
if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
|
|
12961
|
+
reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
|
|
12962
|
+
} else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
|
|
12963
|
+
reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
|
|
12964
|
+
} else {
|
|
12965
|
+
// Otherwise, add new iapMetadata fields to reqObj
|
|
12966
|
+
reqObj[iapField] = iapMetadata[iapField];
|
|
12967
|
+
}
|
|
12968
|
+
}
|
|
12969
|
+
});
|
|
12970
|
+
// Add iapMetadata to reqObj for further work
|
|
12971
|
+
reqObj.iapMetadata = iapMetadata;
|
|
12972
|
+
}
|
|
12973
|
+
|
|
12974
|
+
try {
|
|
12975
|
+
// Make the call -
|
|
12976
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
12977
|
+
return this.requestHandlerInst.identifyRequest('ChangeManagement', 'refreshChangeRequestImpactedServices', reqObj, true, (irReturnData, irReturnError) => {
|
|
12978
|
+
// if we received an error or their is no response on the results
|
|
12979
|
+
// return an error
|
|
12980
|
+
if (irReturnError) {
|
|
12981
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
12982
|
+
return callback(null, irReturnError);
|
|
12983
|
+
}
|
|
12984
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
12985
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['refreshChangeRequestImpactedServices'], null, null, null);
|
|
12986
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12987
|
+
return callback(null, errorObj);
|
|
12988
|
+
}
|
|
12989
|
+
|
|
12990
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
12991
|
+
// return the response
|
|
12992
|
+
return callback(irReturnData, null);
|
|
12993
|
+
});
|
|
12994
|
+
} catch (ex) {
|
|
12995
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
12996
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
12997
|
+
return callback(null, errorObj);
|
|
12998
|
+
}
|
|
12999
|
+
}
|
|
13000
|
+
|
|
13001
|
+
/**
|
|
13002
|
+
* @function getChangeRequestSchedule
|
|
13003
|
+
* @pronghornType method
|
|
13004
|
+
* @name getChangeRequestSchedule
|
|
13005
|
+
* @summary Enables retrieving the available time slots for a change request.
|
|
13006
|
+
*
|
|
13007
|
+
* @param {string} changeSysId - Sys_id of the change request on which to find the next available time slot. Located in the [change_request] table. The selected change request must have a configuration i...(description truncated)
|
|
13008
|
+
* @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
|
|
13009
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
13010
|
+
* @return {object} results - An object containing the response of the action
|
|
13011
|
+
*
|
|
13012
|
+
* @route {POST} /getChangeRequestSchedule
|
|
13013
|
+
* @roles admin
|
|
13014
|
+
* @task true
|
|
13015
|
+
*/
|
|
13016
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
13017
|
+
getChangeRequestSchedule(changeSysId, iapMetadata, callback) {
|
|
13018
|
+
const meth = 'adapter-getChangeRequestSchedule';
|
|
13019
|
+
const origin = `${this.id}-${meth}`;
|
|
13020
|
+
log.trace(origin);
|
|
13021
|
+
|
|
13022
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
13023
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
13024
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
13025
|
+
return callback(null, errorObj);
|
|
13026
|
+
}
|
|
13027
|
+
|
|
13028
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
13029
|
+
if (changeSysId === undefined || changeSysId === null || changeSysId === '') {
|
|
13030
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['changeSysId'], null, null, null);
|
|
13031
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
13032
|
+
return callback(null, errorObj);
|
|
13033
|
+
}
|
|
13034
|
+
|
|
13035
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
13036
|
+
const queryParamsAvailable = {};
|
|
13037
|
+
const queryParams = {};
|
|
13038
|
+
const pathVars = [changeSysId];
|
|
13039
|
+
const bodyVars = {};
|
|
13040
|
+
|
|
13041
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
13042
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
13043
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
13044
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
13045
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
13046
|
+
}
|
|
13047
|
+
});
|
|
13048
|
+
|
|
13049
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
13050
|
+
// see adapter code documentation for more information on the request object's fields
|
|
13051
|
+
const reqObj = {
|
|
13052
|
+
payload: bodyVars,
|
|
13053
|
+
uriPathVars: pathVars,
|
|
13054
|
+
uriQuery: queryParams
|
|
13055
|
+
};
|
|
13056
|
+
|
|
13057
|
+
const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
|
|
13058
|
+
|
|
13059
|
+
// Merge and add new iapMetadata fields in reqObj
|
|
13060
|
+
if (iapMetadata && typeof iapMetadata === 'object') {
|
|
13061
|
+
Object.keys(iapMetadata).forEach((iapField) => {
|
|
13062
|
+
if (reqFields.includes(iapField) && iapMetadata[iapField]) {
|
|
13063
|
+
if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
|
|
13064
|
+
reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
|
|
13065
|
+
} else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
|
|
13066
|
+
reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
|
|
13067
|
+
} else {
|
|
13068
|
+
// Otherwise, add new iapMetadata fields to reqObj
|
|
13069
|
+
reqObj[iapField] = iapMetadata[iapField];
|
|
13070
|
+
}
|
|
13071
|
+
}
|
|
13072
|
+
});
|
|
13073
|
+
// Add iapMetadata to reqObj for further work
|
|
13074
|
+
reqObj.iapMetadata = iapMetadata;
|
|
13075
|
+
}
|
|
13076
|
+
|
|
13077
|
+
try {
|
|
13078
|
+
// Make the call -
|
|
13079
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
13080
|
+
return this.requestHandlerInst.identifyRequest('ChangeManagement', 'getChangeRequestSchedule', reqObj, true, (irReturnData, irReturnError) => {
|
|
13081
|
+
// if we received an error or their is no response on the results
|
|
13082
|
+
// return an error
|
|
13083
|
+
if (irReturnError) {
|
|
13084
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
13085
|
+
return callback(null, irReturnError);
|
|
13086
|
+
}
|
|
13087
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
13088
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getChangeRequestSchedule'], null, null, null);
|
|
13089
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
13090
|
+
return callback(null, errorObj);
|
|
13091
|
+
}
|
|
13092
|
+
|
|
13093
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
13094
|
+
// return the response
|
|
13095
|
+
return callback(irReturnData, null);
|
|
13096
|
+
});
|
|
13097
|
+
} catch (ex) {
|
|
13098
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
13099
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
13100
|
+
return callback(null, errorObj);
|
|
13101
|
+
}
|
|
13102
|
+
}
|
|
13103
|
+
|
|
13104
|
+
/**
|
|
13105
|
+
* @function updateChangeRequestFirstAvailableSchedule
|
|
13106
|
+
* @pronghornType method
|
|
13107
|
+
* @name updateChangeRequestFirstAvailableSchedule
|
|
13108
|
+
* @summary Updates the planned start and end times of a change request using the first available time slot fou
|
|
13109
|
+
*
|
|
13110
|
+
* @param {string} changeSysId - Sys_id of the change request on which to update with the next available time slot. Located in the Change Requests [change_request] table. The selected change request must...(description truncated)
|
|
13111
|
+
* @param {object} body - body param
|
|
13112
|
+
* @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
|
|
13113
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
13114
|
+
* @return {object} results - An object containing the response of the action
|
|
13115
|
+
*
|
|
13116
|
+
* @route {POST} /updateChangeRequestFirstAvailableSchedule
|
|
13117
|
+
* @roles admin
|
|
13118
|
+
* @task true
|
|
13119
|
+
*/
|
|
13120
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
13121
|
+
updateChangeRequestFirstAvailableSchedule(changeSysId, body, iapMetadata, callback) {
|
|
13122
|
+
const meth = 'adapter-updateChangeRequestFirstAvailableSchedule';
|
|
13123
|
+
const origin = `${this.id}-${meth}`;
|
|
13124
|
+
log.trace(origin);
|
|
13125
|
+
|
|
13126
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
13127
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
13128
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
13129
|
+
return callback(null, errorObj);
|
|
13130
|
+
}
|
|
13131
|
+
|
|
13132
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
13133
|
+
if (changeSysId === undefined || changeSysId === null || changeSysId === '') {
|
|
13134
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['changeSysId'], null, null, null);
|
|
13135
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
13136
|
+
return callback(null, errorObj);
|
|
13137
|
+
}
|
|
13138
|
+
if (body === undefined || body === null || body === '') {
|
|
13139
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
|
|
13140
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
13141
|
+
return callback(null, errorObj);
|
|
13142
|
+
}
|
|
13143
|
+
|
|
13144
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
13145
|
+
const queryParamsAvailable = {};
|
|
13146
|
+
const queryParams = {};
|
|
13147
|
+
const pathVars = [changeSysId];
|
|
13148
|
+
const bodyVars = body;
|
|
13149
|
+
|
|
13150
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
13151
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
13152
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
13153
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
13154
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
13155
|
+
}
|
|
13156
|
+
});
|
|
13157
|
+
|
|
13158
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
13159
|
+
// see adapter code documentation for more information on the request object's fields
|
|
13160
|
+
const reqObj = {
|
|
13161
|
+
payload: bodyVars,
|
|
13162
|
+
uriPathVars: pathVars,
|
|
13163
|
+
uriQuery: queryParams
|
|
13164
|
+
};
|
|
13165
|
+
|
|
13166
|
+
const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
|
|
13167
|
+
|
|
13168
|
+
// Merge and add new iapMetadata fields in reqObj
|
|
13169
|
+
if (iapMetadata && typeof iapMetadata === 'object') {
|
|
13170
|
+
Object.keys(iapMetadata).forEach((iapField) => {
|
|
13171
|
+
if (reqFields.includes(iapField) && iapMetadata[iapField]) {
|
|
13172
|
+
if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
|
|
13173
|
+
reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
|
|
13174
|
+
} else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
|
|
13175
|
+
reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
|
|
13176
|
+
} else {
|
|
13177
|
+
// Otherwise, add new iapMetadata fields to reqObj
|
|
13178
|
+
reqObj[iapField] = iapMetadata[iapField];
|
|
13179
|
+
}
|
|
13180
|
+
}
|
|
13181
|
+
});
|
|
13182
|
+
// Add iapMetadata to reqObj for further work
|
|
13183
|
+
reqObj.iapMetadata = iapMetadata;
|
|
13184
|
+
}
|
|
13185
|
+
|
|
13186
|
+
try {
|
|
13187
|
+
// Make the call -
|
|
13188
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
13189
|
+
return this.requestHandlerInst.identifyRequest('ChangeManagement', 'updateChangeRequestFirstAvailableSchedule', reqObj, true, (irReturnData, irReturnError) => {
|
|
13190
|
+
// if we received an error or their is no response on the results
|
|
13191
|
+
// return an error
|
|
13192
|
+
if (irReturnError) {
|
|
13193
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
13194
|
+
return callback(null, irReturnError);
|
|
13195
|
+
}
|
|
13196
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
13197
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['updateChangeRequestFirstAvailableSchedule'], null, null, null);
|
|
13198
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
13199
|
+
return callback(null, errorObj);
|
|
13200
|
+
}
|
|
13201
|
+
|
|
13202
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
13203
|
+
// return the response
|
|
13204
|
+
return callback(irReturnData, null);
|
|
13205
|
+
});
|
|
13206
|
+
} catch (ex) {
|
|
13207
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
13208
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
13209
|
+
return callback(null, errorObj);
|
|
13210
|
+
}
|
|
13211
|
+
}
|
|
13212
|
+
|
|
13213
|
+
/**
|
|
13214
|
+
* @function updateChangeTaskByTaskId
|
|
13215
|
+
* @pronghornType method
|
|
13216
|
+
* @name updateChangeTaskByTaskId
|
|
13217
|
+
* @summary Updates the change request task identified by the specified sys_ids with the key-value pairs in the
|
|
13218
|
+
*
|
|
13219
|
+
* @param {string} changeSysId - Sys_id of the change request to which the task is associated. Verifies whether the specified task is associated with the specified change request. Located in the Change R...(description truncated)
|
|
13220
|
+
* @param {string} taskSysId - Sys_id of the task to modify. Located in the Change Task [change_task] table.
|
|
13221
|
+
* @param {object} [sysparmQueryKeyValuePairs] - e.g. { number: 'CHG12345' }
|
|
13222
|
+
* @param {string} [sysparmQueryString] - e.g. number=CHG12345
|
|
13223
|
+
* @param {object} body - body param
|
|
13224
|
+
* @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
|
|
13225
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
13226
|
+
* @return {object} results - An object containing the response of the action
|
|
13227
|
+
*
|
|
13228
|
+
* @route {POST} /updateChangeTaskByTaskId
|
|
13229
|
+
* @roles admin
|
|
13230
|
+
* @task true
|
|
13231
|
+
*/
|
|
13232
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
13233
|
+
updateChangeTaskByTaskId(changeSysId, taskSysId, sysparmQueryKeyValuePairs, sysparmQueryString, body, iapMetadata, callback) {
|
|
13234
|
+
const meth = 'adapter-updateChangeTaskByTaskId';
|
|
13235
|
+
const origin = `${this.id}-${meth}`;
|
|
13236
|
+
log.trace(origin);
|
|
13237
|
+
|
|
13238
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
13239
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
13240
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
13241
|
+
return callback(null, errorObj);
|
|
13242
|
+
}
|
|
13243
|
+
|
|
13244
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
13245
|
+
if (changeSysId === undefined || changeSysId === null || changeSysId === '') {
|
|
13246
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['changeSysId'], null, null, null);
|
|
13247
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
13248
|
+
return callback(null, errorObj);
|
|
13249
|
+
}
|
|
13250
|
+
if (taskSysId === undefined || taskSysId === null || taskSysId === '') {
|
|
13251
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['taskSysId'], null, null, null);
|
|
13252
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
13253
|
+
return callback(null, errorObj);
|
|
13254
|
+
}
|
|
13255
|
+
if (body === undefined || body === null || body === '') {
|
|
13256
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
|
|
13257
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
13258
|
+
return callback(null, errorObj);
|
|
13259
|
+
}
|
|
13260
|
+
|
|
13261
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
13262
|
+
const queryParamsAvailable = { ...sysparmQueryKeyValuePairs };
|
|
13263
|
+
const queryParams = {};
|
|
13264
|
+
const pathVars = [changeSysId, taskSysId];
|
|
13265
|
+
const bodyVars = body;
|
|
13266
|
+
|
|
13267
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
13268
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
13269
|
+
if (thisKeyInQueryParamsAvailable !== 'sysparmQuery' && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined
|
|
13270
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
13271
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
13272
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
13273
|
+
}
|
|
13274
|
+
});
|
|
13275
|
+
|
|
13276
|
+
if (sysparmQueryString !== undefined && sysparmQueryString !== null && sysparmQueryString !== '') {
|
|
13277
|
+
queryParams.sysparmQuery = sysparmQueryString;
|
|
13278
|
+
} else if (sysparmQueryKeyValuePairs !== undefined && sysparmQueryKeyValuePairs !== null
|
|
13279
|
+
&& sysparmQueryKeyValuePairs.sysparmQuery !== undefined && sysparmQueryKeyValuePairs.sysparmQuery !== null
|
|
13280
|
+
&& sysparmQueryKeyValuePairs.sysparmQuery !== '') {
|
|
13281
|
+
queryParams.sysparmQuery = sysparmQueryKeyValuePairs.sysparmQuery;
|
|
13282
|
+
}
|
|
13283
|
+
|
|
13284
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
13285
|
+
// see adapter code documentation for more information on the request object's fields
|
|
13286
|
+
const reqObj = {
|
|
13287
|
+
payload: bodyVars,
|
|
13288
|
+
uriPathVars: pathVars,
|
|
13289
|
+
uriQuery: queryParams
|
|
13290
|
+
};
|
|
13291
|
+
|
|
13292
|
+
const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
|
|
13293
|
+
|
|
13294
|
+
// Merge and add new iapMetadata fields in reqObj
|
|
13295
|
+
if (iapMetadata && typeof iapMetadata === 'object') {
|
|
13296
|
+
Object.keys(iapMetadata).forEach((iapField) => {
|
|
13297
|
+
if (reqFields.includes(iapField) && iapMetadata[iapField]) {
|
|
13298
|
+
if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
|
|
13299
|
+
reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
|
|
13300
|
+
} else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
|
|
13301
|
+
reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
|
|
13302
|
+
} else {
|
|
13303
|
+
// Otherwise, add new iapMetadata fields to reqObj
|
|
13304
|
+
reqObj[iapField] = iapMetadata[iapField];
|
|
13305
|
+
}
|
|
13306
|
+
}
|
|
13307
|
+
});
|
|
13308
|
+
// Add iapMetadata to reqObj for further work
|
|
13309
|
+
reqObj.iapMetadata = iapMetadata;
|
|
13310
|
+
}
|
|
13311
|
+
|
|
13312
|
+
try {
|
|
13313
|
+
// Make the call -
|
|
13314
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
13315
|
+
return this.requestHandlerInst.identifyRequest('ChangeManagement', 'updateChangeTaskByTaskId', reqObj, true, (irReturnData, irReturnError) => {
|
|
13316
|
+
// if we received an error or their is no response on the results
|
|
13317
|
+
// return an error
|
|
13318
|
+
if (irReturnError) {
|
|
13319
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
13320
|
+
return callback(null, irReturnError);
|
|
13321
|
+
}
|
|
13322
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
13323
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['updateChangeTaskByTaskId'], null, null, null);
|
|
13324
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
13325
|
+
return callback(null, errorObj);
|
|
13326
|
+
}
|
|
13327
|
+
|
|
13328
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
13329
|
+
// return the response
|
|
13330
|
+
return callback(irReturnData, null);
|
|
13331
|
+
});
|
|
13332
|
+
} catch (ex) {
|
|
13333
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
13334
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
13335
|
+
return callback(null, errorObj);
|
|
13336
|
+
}
|
|
13337
|
+
}
|
|
13338
|
+
|
|
13339
|
+
/**
|
|
13340
|
+
* @function updateChangeRequestRisk
|
|
13341
|
+
* @pronghornType method
|
|
13342
|
+
* @name updateChangeRequestRisk
|
|
13343
|
+
* @summary Calculates the risk and impact of the specified standard change based on an evaluation of the risk
|
|
13344
|
+
*
|
|
13345
|
+
* @param {string} sysId - Sys_id of the standard change to evaluate. Located in the Change Request [change_request] table.
|
|
13346
|
+
* @param {object} body - body param
|
|
13347
|
+
* @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
|
|
13348
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
13349
|
+
* @return {object} results - An object containing the response of the action
|
|
13350
|
+
*
|
|
13351
|
+
* @route {POST} /updateChangeRequestRisk
|
|
13352
|
+
* @roles admin
|
|
13353
|
+
* @task true
|
|
13354
|
+
*/
|
|
13355
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
13356
|
+
updateChangeRequestRisk(sysId, body, iapMetadata, callback) {
|
|
13357
|
+
const meth = 'adapter-updateChangeRequestRisk';
|
|
13358
|
+
const origin = `${this.id}-${meth}`;
|
|
13359
|
+
log.trace(origin);
|
|
13360
|
+
|
|
13361
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
13362
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
13363
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
13364
|
+
return callback(null, errorObj);
|
|
13365
|
+
}
|
|
13366
|
+
|
|
13367
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
13368
|
+
if (sysId === undefined || sysId === null || sysId === '') {
|
|
13369
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['sysId'], null, null, null);
|
|
13370
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
13371
|
+
return callback(null, errorObj);
|
|
13372
|
+
}
|
|
13373
|
+
if (body === undefined || body === null || body === '') {
|
|
13374
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
|
|
13375
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
13376
|
+
return callback(null, errorObj);
|
|
13377
|
+
}
|
|
13378
|
+
|
|
13379
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
13380
|
+
const queryParamsAvailable = {};
|
|
13381
|
+
const queryParams = {};
|
|
13382
|
+
const pathVars = [sysId];
|
|
13383
|
+
const bodyVars = body;
|
|
13384
|
+
|
|
13385
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
13386
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
13387
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
13388
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
13389
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
13390
|
+
}
|
|
13391
|
+
});
|
|
13392
|
+
|
|
13393
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
13394
|
+
// see adapter code documentation for more information on the request object's fields
|
|
13395
|
+
const reqObj = {
|
|
13396
|
+
payload: bodyVars,
|
|
13397
|
+
uriPathVars: pathVars,
|
|
13398
|
+
uriQuery: queryParams
|
|
13399
|
+
};
|
|
13400
|
+
|
|
13401
|
+
const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
|
|
13402
|
+
|
|
13403
|
+
// Merge and add new iapMetadata fields in reqObj
|
|
13404
|
+
if (iapMetadata && typeof iapMetadata === 'object') {
|
|
13405
|
+
Object.keys(iapMetadata).forEach((iapField) => {
|
|
13406
|
+
if (reqFields.includes(iapField) && iapMetadata[iapField]) {
|
|
13407
|
+
if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
|
|
13408
|
+
reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
|
|
13409
|
+
} else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
|
|
13410
|
+
reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
|
|
13411
|
+
} else {
|
|
13412
|
+
// Otherwise, add new iapMetadata fields to reqObj
|
|
13413
|
+
reqObj[iapField] = iapMetadata[iapField];
|
|
13414
|
+
}
|
|
13415
|
+
}
|
|
13416
|
+
});
|
|
13417
|
+
// Add iapMetadata to reqObj for further work
|
|
13418
|
+
reqObj.iapMetadata = iapMetadata;
|
|
13419
|
+
}
|
|
13420
|
+
|
|
13421
|
+
try {
|
|
13422
|
+
// Make the call -
|
|
13423
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
13424
|
+
return this.requestHandlerInst.identifyRequest('ChangeManagement', 'updateChangeRequestRisk', reqObj, true, (irReturnData, irReturnError) => {
|
|
13425
|
+
// if we received an error or their is no response on the results
|
|
13426
|
+
// return an error
|
|
13427
|
+
if (irReturnError) {
|
|
13428
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
13429
|
+
return callback(null, irReturnError);
|
|
13430
|
+
}
|
|
13431
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
13432
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['updateChangeRequestRisk'], null, null, null);
|
|
13433
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
13434
|
+
return callback(null, errorObj);
|
|
13435
|
+
}
|
|
13436
|
+
|
|
13437
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
13438
|
+
// return the response
|
|
13439
|
+
return callback(irReturnData, null);
|
|
13440
|
+
});
|
|
13441
|
+
} catch (ex) {
|
|
13442
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
13443
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
13444
|
+
return callback(null, errorObj);
|
|
13445
|
+
}
|
|
13446
|
+
}
|
|
13447
|
+
|
|
13448
|
+
/**
|
|
13449
|
+
* @function updateStandardChangeRequestById
|
|
13450
|
+
* @pronghornType method
|
|
13451
|
+
* @name updateStandardChangeRequestById
|
|
13452
|
+
* @summary Updates the standard change request identified by the specified sys_id with the parameters in the r
|
|
13453
|
+
*
|
|
13454
|
+
* @param {string} sysId - Sys_id of the change request to modify. Located in the [change_request] table.
|
|
13455
|
+
* @param {object} [sysparmQueryKeyValuePairs] - e.g. { number: 'CHG12345' }
|
|
13456
|
+
* @param {string} [sysparmQueryString] - e.g. number=CHG12345
|
|
13457
|
+
* @param {object} body - body param
|
|
13458
|
+
* @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
|
|
13459
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
13460
|
+
* @return {object} results - An object containing the response of the action
|
|
13461
|
+
*
|
|
13462
|
+
* @route {POST} /updateStandardChangeRequestById
|
|
13463
|
+
* @roles admin
|
|
13464
|
+
* @task true
|
|
13465
|
+
*/
|
|
13466
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
13467
|
+
updateStandardChangeRequestById(sysId, sysparmQueryKeyValuePairs, sysparmQueryString, body, iapMetadata, callback) {
|
|
13468
|
+
const meth = 'adapter-updateStandardChangeRequestById';
|
|
13469
|
+
const origin = `${this.id}-${meth}`;
|
|
13470
|
+
log.trace(origin);
|
|
13471
|
+
|
|
13472
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
13473
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
13474
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
13475
|
+
return callback(null, errorObj);
|
|
13476
|
+
}
|
|
13477
|
+
|
|
13478
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
13479
|
+
if (sysId === undefined || sysId === null || sysId === '') {
|
|
13480
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['sysId'], null, null, null);
|
|
13481
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
13482
|
+
return callback(null, errorObj);
|
|
13483
|
+
}
|
|
13484
|
+
if (body === undefined || body === null || body === '') {
|
|
13485
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
|
|
13486
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
13487
|
+
return callback(null, errorObj);
|
|
13488
|
+
}
|
|
13489
|
+
|
|
13490
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
13491
|
+
const queryParamsAvailable = { ...sysparmQueryKeyValuePairs };
|
|
13492
|
+
const queryParams = {};
|
|
13493
|
+
const pathVars = [sysId];
|
|
13494
|
+
const bodyVars = body;
|
|
13495
|
+
|
|
13496
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
13497
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
13498
|
+
if (thisKeyInQueryParamsAvailable !== 'sysparmQuery' && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined
|
|
13499
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
13500
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
13501
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
13502
|
+
}
|
|
13503
|
+
});
|
|
13504
|
+
|
|
13505
|
+
if (sysparmQueryString !== undefined && sysparmQueryString !== null && sysparmQueryString !== '') {
|
|
13506
|
+
queryParams.sysparmQuery = sysparmQueryString;
|
|
13507
|
+
} else if (sysparmQueryKeyValuePairs !== undefined && sysparmQueryKeyValuePairs !== null
|
|
13508
|
+
&& sysparmQueryKeyValuePairs.sysparmQuery !== undefined && sysparmQueryKeyValuePairs.sysparmQuery !== null
|
|
13509
|
+
&& sysparmQueryKeyValuePairs.sysparmQuery !== '') {
|
|
13510
|
+
queryParams.sysparmQuery = sysparmQueryKeyValuePairs.sysparmQuery;
|
|
13511
|
+
}
|
|
13512
|
+
|
|
13513
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
13514
|
+
// see adapter code documentation for more information on the request object's fields
|
|
13515
|
+
const reqObj = {
|
|
13516
|
+
payload: bodyVars,
|
|
13517
|
+
uriPathVars: pathVars,
|
|
13518
|
+
uriQuery: queryParams
|
|
13519
|
+
};
|
|
13520
|
+
|
|
13521
|
+
const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
|
|
13522
|
+
|
|
13523
|
+
// Merge and add new iapMetadata fields in reqObj
|
|
13524
|
+
if (iapMetadata && typeof iapMetadata === 'object') {
|
|
13525
|
+
Object.keys(iapMetadata).forEach((iapField) => {
|
|
13526
|
+
if (reqFields.includes(iapField) && iapMetadata[iapField]) {
|
|
13527
|
+
if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
|
|
13528
|
+
reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
|
|
13529
|
+
} else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
|
|
13530
|
+
reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
|
|
13531
|
+
} else {
|
|
13532
|
+
// Otherwise, add new iapMetadata fields to reqObj
|
|
13533
|
+
reqObj[iapField] = iapMetadata[iapField];
|
|
13534
|
+
}
|
|
13535
|
+
}
|
|
13536
|
+
});
|
|
13537
|
+
// Add iapMetadata to reqObj for further work
|
|
13538
|
+
reqObj.iapMetadata = iapMetadata;
|
|
13539
|
+
}
|
|
13540
|
+
|
|
13541
|
+
try {
|
|
13542
|
+
// Make the call -
|
|
13543
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
13544
|
+
return this.requestHandlerInst.identifyRequest('ChangeManagement', 'updateStandardChangeRequestById', reqObj, true, (irReturnData, irReturnError) => {
|
|
13545
|
+
// if we received an error or their is no response on the results
|
|
13546
|
+
// return an error
|
|
13547
|
+
if (irReturnError) {
|
|
13548
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
13549
|
+
return callback(null, irReturnError);
|
|
13550
|
+
}
|
|
13551
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
13552
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['updateStandardChangeRequestById'], null, null, null);
|
|
13553
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
13554
|
+
return callback(null, errorObj);
|
|
13555
|
+
}
|
|
13556
|
+
|
|
13557
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
13558
|
+
// return the response
|
|
13559
|
+
return callback(irReturnData, null);
|
|
13560
|
+
});
|
|
13561
|
+
} catch (ex) {
|
|
13562
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
13563
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
13564
|
+
return callback(null, errorObj);
|
|
13565
|
+
}
|
|
13566
|
+
}
|
|
11465
13567
|
}
|
|
11466
13568
|
|
|
11467
13569
|
module.exports = Servicenow;
|