We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Could someone please explain the below code?

Venkat141
Tera Contributor

Could someone please explain what and how it's querying. and what is options.sys_class_list?

 

// populate the 'data' object
// e.g., data.table = $sp.getValue('table');
data.outageArr = [];
data.degradationArr = [];
data.plannedArr = [];
var outage = new GlideRecord("cmdb_ci_outage");
outage.addQuery("cmdb_ci.sys_class_name", "IN", options.sys_class_list || "cmdb_ci_service");
outage.addQuery("begin", "<=", gs.nowNoTZ());
 
outage.addQuery("end", ">=", gs.nowNoTZ()).addOrCondition("end", "=", "NULL");
data.service = (input && input.service) || $sp.getParameter("service");
if (!GlideStringUtil.nil(data.service)) {
  outage.addQuery("cmdb_ci", data.service);
var serviceGR = new GlideRecord("cmdb_ci_service");
if (serviceGR.get(data.service))
data.serviceDisplay = serviceGR.getDisplayValue();
}
outage.query();
data.outages = [];
data.outageIDs = "";
while (outage.next()) {
var out = {};
out.typeDisplay = outage.type.getDisplayValue();
out.type = outage.getValue("type");
out.details = outage.getValue("details");
out.ci = outage.cmdb_ci.getDisplayValue();
out.serviceID = outage.getValue("cmdb_ci");
out.begin = outage.begin.getDisplayValue();
if(outage.getValue('type') == 'outage'){
data.outageArr.push(out);
}
else if(outage.getValue('type') == 'degradation'){
data.degradationArr.push(out);
}
else if(outage.getValue('type') == 'planned'){
data.plannedArr.push(out);
}
else
  data.outages.push(out);
data.outageIDs += "," + outage.getUniqueValue();
}
data.outages = data.outageArr.concat(data.degradationArr);
data.outages = data.outages.concat(data.plannedArr);

 

1 REPLY 1

Harish Bainsla
Kilo Patron

Hi

It seems to be querying a ServiceNow table called "cmdb_ci_outage" to retrieve outage records based on certain criteria.

Overall, this script retrieves outage records from the "cmdb_ci_outage" table based on certain criteria, categorizes them by type, and prepares the data for further processing or display, likely in a ServiceNow application or interface.