(function execute(inputs, outputs) {
// --- Part 1: Get all incident sys_Id values ---
var groupSkillId;
var action_skill_id; // Declare action_skill_id
var recSysId = [Link]([Link], 'number', inputs.record_number);
switch ([Link]) {
case 'incident':
groupSkillId = UXCConstants.ITSM_GROUPING;
action_skill_id = UXCConstants.ITSM_ACTION_STRATEGY;
break;
case 'sn_customerservice_case':
groupSkillId = UXCConstants.CSM_GROUPING;
action_skill_id = UXCConstants.CSM_ACTION_STRATEGY;
break;
case 'sn_hr_core_case':
groupSkillId = UXCConstants.HR_GROUPING;
action_skill_id = UXCConstants.HR_ACTION_STRATEGY;
break;
default:
break;
}
var grpSysId = [Link](recSysId, [Link], inputs.record_number,
groupSkillId);
var recs;
if (grpSysId) {
recs = [Link](grpSysId, groupSkillId);
} else {
recs = [Link]([Link], recSysId);
}
[Link] = [Link](recs);
var incidentSysIds = [];
if ([Link](recs)) {
for (var i = 0; i < [Link]; i++) {
var item = recs[i];
if (item && item.sys_Id) {
[Link](item.sys_Id);
}
}
}
outputs.sys_ids = [Link](incidentSysIds);
var allOutagesReport = "";
var incidentsWithOutagesCount = 0;
if ([Link] === 0) {
allOutagesReport = "No incident sys_IDs found to query for outages.";
[Link](allOutagesReport);
outputs.outage_report = allOutagesReport;
return;
}
for (var j = 0; j < [Link]; j++) {
var currentIncidentId = incidentSysIds[j];
var incidentNumber = "";
var currentIncidentOutageSection = "";
var incGR = new GlideRecord('incident');
if ([Link](currentIncidentId)) {
incidentNumber = [Link];
} else {
incidentNumber = "NOT FOUND";
[Link]("Incident record with sys_id '" + currentIncidentId + "' not found or inaccessible.");
}
currentIncidentOutageSection += "\n--- Outages for Incident: " + incidentNumber + " (Sys ID: "
+ currentIncidentId + ") ---\n";
var outageGR = new GlideRecord('cmdb_ci_outage');
[Link]('task_number', currentIncidentId);
[Link]();
if ([Link]()) {
incidentsWithOutagesCount++;
while ([Link]()) {
currentIncidentOutageSection += " ----------------------------------------\n";
currentIncidentOutageSection += " Outage Sys ID: " + outageGR.sys_id + "\n";
currentIncidentOutageSection += " Outage Number: " + [Link] + "\n";
currentIncidentOutageSection += " Begin: " + [Link]() + "\n";
currentIncidentOutageSection += " End: " + [Link]() + "\n";
currentIncidentOutageSection += " Description: " + [Link] + "\n";
currentIncidentOutageSection += " ----------------------------------------\n";
}
allOutagesReport += currentIncidentOutageSection;
} else {
[Link]("Incident " + incidentNumber + " (" + currentIncidentId + "): No related outages
found.");
}
}
if (incidentsWithOutagesCount === 0 && [Link] > 0) {
allOutagesReport = "No incidents with related outage records were found among the " +
[Link] + " processed incidents.";
[Link](allOutagesReport);
} else if (incidentsWithOutagesCount === 0 && [Link] === 0) {
allOutagesReport = "No incident sys_IDs found to query for outages.";
[Link](allOutagesReport);
}
outputs.outage_details = allOutagesReport;
})(inputs, outputs);