Prevent a certain type of change tasks to be copied over when clicking Copy Change
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2022 08:58 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2022 09:36 PM
Hi Evren,
In the Script where Change Task are getting copied, you can filter out Change Task with Type as Review.
Please mark this as correct answer if it resolved, or mark this helpful if this help you to reach towards solution.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2022 09:41 PM
Hi Evren,
Can you show how you enabled Copy Change Task and script used inside it?
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2022 10:02 PM
I have added the name of the table (change_task) on this OOB property(com.snc.change_request.copy.related_lists).
And here is the OOB code that it uses to copy the related tables including the change_task. Not really sure though how I can add the condition to prevent copying the review type change tasks.
makeRelatedTableCopy: function( /*String*/ srcParentSysId,
/*String*/ targetParentSysId,
/*String*/ table,
/*String*/ key, /*If provided, used to prevent duplicate rows*/
/*String*/ parentAttr,
/*Array*/ copyAttrs,
/*Boolean*/ copyAttachments,
/*CSV String*/ copyChildRelatedLists) {
if (!copyChildRelatedLists)
copyChildRelatedLists = [];
else
copyChildRelatedLists = this.getCsvValue(copyChildRelatedLists);
var ans = [];
copyAttrs = this.arrayUtil.diff(copyAttrs, this.ALWAYS_IGNORE_ATTRS, [
parentAttr
]);
var srcGr = new GlideRecordSecure(table);
if (srcGr.isValid()) {
var existingRecords = [];
srcGr.addQuery(parentAttr, srcParentSysId);
//Check if table is task_ci and if so exclude dynamic added CI as these will be processed when the dynamic CI is inserted
if (table === this.TASK_CI)
srcGr.addNullQuery('added_from_dynamic_ci');
srcGr.query();
if (key) {
existingRecords = this._getTargetRelatedRecordKeys(table, key,
parentAttr, targetParentSysId);
}
while (srcGr.next()) {
if (key
&& this.arrayUtil.contains(existingRecords, srcGr.getValue(key)))
continue;
if ((table === this.CHANGE_TASK) && (srcGr.getValue(this.TASK_CREATED_FROM) === this.TASK_CREATED_FROM_WORKFLOW || srcGr.getValue(this.TASK_CREATED_FROM) === this.TASK_CREATED_FROM_FLOW))
continue;
var newSysId = this._makeRelatedRecordCopy(srcGr, copyAttrs,
parentAttr, targetParentSysId);
if (newSysId) {
ans.push(newSysId);
if (copyAttachments)
this._copyAttachments(srcGr, newSysId);
for (var i = 0; i < copyChildRelatedLists.length; ++i) {
var relatedTable = copyChildRelatedLists[i];
var newAns = this._makeRelatedTableCopy(srcGr.getUniqueValue(),
newSysId, relatedTable);
if (!this._isSet(newAns)) {
this.log.logWarning('makeRelatedTableCopy: Could not copy related\'s related table ' +
relatedTable);
}
}
} else {
this.log.logWarning('makeRelatedTableCopy: Could not copy related table ' + table);
}
}
return ans;
} else {
this.log.logWarning('makeRelatedTableCopy: Invalid table ' + table);
}
},
_makeRelatedTableCopy: function(srcParentSysId, targetParentSysId, table) {
var map = this.RELATED_TABLES_MAP[table];
if (!map) {
this.log.logWarning('_makeRelatedTableCopy: Unsupported related table ' + table);
return;
}
var key = map.key;
var parentAttr = map.parentAttr;
var attachmentKey = map.copyAttachmentsKey;
var copyAttachments = false;
if (attachmentKey)
copyAttachments = this._getCsvPropertyValue(attachmentKey, 'true') == 'true';
var copyAttrs = this._getCsvPropertyValue(map.property,
map.defaultValue);
var copyChildRelatedLists = map['copyRelated'];
return this.makeRelatedTableCopy(srcParentSysId, targetParentSysId, table,
key, parentAttr, copyAttrs,
copyAttachments, copyChildRelatedLists);
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2023 11:58 PM
Could you kindly share the script and tell us where you have applied this validation?