- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2025 12:48 PM
When CIs are added to the Affected CIs tab on a Change Request, they are stored on the task_ci table. This table links the CIs to the specific Change Request task. I need help querying the task_ci table, validate those CIs that have been linked to the specific Change Request task and ensure only those CIs can be inserted into the cmdb_outage_ci_mtom table where Outage record Affected CIs are stored.
[Summary: when adding CIs to the outage record, only allow CIs that are already listed in the Change's 'Affected CIs' tab. We want to prevent creation of outage records containing CIs not listed as affected in the change.]
I've tested this BR script below and others but got nothing. Any corrections to the script or alternative script to achieve the result is much appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2025 05:17 AM
@SNLearnAll - Your script logic is absolutely correct with some issue with the field names you used from Outage [cmdb_ci_outage] table and Affected CI [task_ci]. Please check with the below script
gs.log("BR Debug - Outage ID: " + current.outage.task_number, "OutageBR");
// Query the change request (task) from the outage record
var outageGR = new GlideRecord('cmdb_ci_outage');
if (outageGR.get(current.outage)) {
var changeRequestId = outageGR.task_number; // You need to use "outageGR.task_numer" instead of "outageGR.task"
gs.log("BR Debug - Associated Change Request: " + changeRequestId, "OutageBR");
// Query the task_ci table to find CIs linked to the change request
var taskCiGR = new GlideRecord('task_ci');
taskCiGR.addQuery('task', changeRequestId);
taskCiGR.addQuery('ci_item', current.ci_item); // You need to use "current.ci_item" instead of "current.cmdb_ci"
taskCiGR.query();
if (!taskCiGR.hasNext()) {
gs.log("BR Debug - CI not found in Affected CIs list. Aborting insert.", "OutageBR");
current.setAbortAction(true); // Prevent insert
} else {
gs.log("BR Debug - CI validated and found in Affected CIs list. Proceeding with insert.", "OutageBR");
}
} else {
gs.log("BR Debug - Outage record not found. Aborting insert.", "OutageBR");
current.setAbortAction(true);
}
.
Thanks & Regards,
Vasanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2025 05:17 AM
@SNLearnAll - Your script logic is absolutely correct with some issue with the field names you used from Outage [cmdb_ci_outage] table and Affected CI [task_ci]. Please check with the below script
gs.log("BR Debug - Outage ID: " + current.outage.task_number, "OutageBR");
// Query the change request (task) from the outage record
var outageGR = new GlideRecord('cmdb_ci_outage');
if (outageGR.get(current.outage)) {
var changeRequestId = outageGR.task_number; // You need to use "outageGR.task_numer" instead of "outageGR.task"
gs.log("BR Debug - Associated Change Request: " + changeRequestId, "OutageBR");
// Query the task_ci table to find CIs linked to the change request
var taskCiGR = new GlideRecord('task_ci');
taskCiGR.addQuery('task', changeRequestId);
taskCiGR.addQuery('ci_item', current.ci_item); // You need to use "current.ci_item" instead of "current.cmdb_ci"
taskCiGR.query();
if (!taskCiGR.hasNext()) {
gs.log("BR Debug - CI not found in Affected CIs list. Aborting insert.", "OutageBR");
current.setAbortAction(true); // Prevent insert
} else {
gs.log("BR Debug - CI validated and found in Affected CIs list. Proceeding with insert.", "OutageBR");
}
} else {
gs.log("BR Debug - Outage record not found. Aborting insert.", "OutageBR");
current.setAbortAction(true);
}
.
Thanks & Regards,
Vasanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2025 01:17 PM
@Vasantharajan NThank you! I applied your suggested adjustments, and the script produced the expected results.