Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

CI Operational Status

Robert P_
Tera Contributor

Any suggestions on how the operational status can change from Non-Operational to Operational if the CI gets re-discovered?

1 ACCEPTED SOLUTION

MarkM1172412930
Tera Guru

We did a business rule so if the user changes it from Non-Operational to Operational, or if the Most Recently Discovered date changes it will handle that. If a user changes the status it just leaves a note, but if the most recently discovered date changes it changes it to operational. This was done prior to flow designer, but I imagine you can do something similar using that as well. Here is the script we put in the Business Rule:

 

(function executeRule(current, previous /*null when async*/ ) {

//Only flag Operational Status field when it's chnaged from non-operational to operataionl.

//check for discovery scan
if (current.last_discovered.changes() && current.last_discovered >= gs.now()) {
if (current.operational_status == 2) { //if changing from non-operational to operational then we flag it.
current.operational_status = 1;
current.u_operational_source = "Discovery";
current.u_work_notes = 'System changed the operational status from "Non-Operational" to "Operational" because CI was recently discovered on ' + gs.now();


}
//if it's changed to operational we leave it as blank

//check user changed status
} else if (current.operational_status.changes()) {
if (current.operational_status == 1) {
current.u_work_notes = 'User changed the operational status to "Operational" on ' + gs.now();
current.u_operational_source = "Manual";
} else if (current.operational_status == 2) {
current.u_work_notes = 'User changed the operational status to "Non-Operational" on ' + gs.now();
if (current.u_operational_source != "") {
current.u_operational_source = ""; //clear the flag
}
}
}

if (current.operational_status == 2) { //not operational
current.u_decommissioned = gs.nowDateTime();
} else {
current.u_decommissioned = '';
}


})(current, previous);

View solution in original post

4 REPLIES 4

MarkM1172412930
Tera Guru

We did a business rule so if the user changes it from Non-Operational to Operational, or if the Most Recently Discovered date changes it will handle that. If a user changes the status it just leaves a note, but if the most recently discovered date changes it changes it to operational. This was done prior to flow designer, but I imagine you can do something similar using that as well. Here is the script we put in the Business Rule:

 

(function executeRule(current, previous /*null when async*/ ) {

//Only flag Operational Status field when it's chnaged from non-operational to operataionl.

//check for discovery scan
if (current.last_discovered.changes() && current.last_discovered >= gs.now()) {
if (current.operational_status == 2) { //if changing from non-operational to operational then we flag it.
current.operational_status = 1;
current.u_operational_source = "Discovery";
current.u_work_notes = 'System changed the operational status from "Non-Operational" to "Operational" because CI was recently discovered on ' + gs.now();


}
//if it's changed to operational we leave it as blank

//check user changed status
} else if (current.operational_status.changes()) {
if (current.operational_status == 1) {
current.u_work_notes = 'User changed the operational status to "Operational" on ' + gs.now();
current.u_operational_source = "Manual";
} else if (current.operational_status == 2) {
current.u_work_notes = 'User changed the operational status to "Non-Operational" on ' + gs.now();
if (current.u_operational_source != "") {
current.u_operational_source = ""; //clear the flag
}
}
}

if (current.operational_status == 2) { //not operational
current.u_decommissioned = gs.nowDateTime();
} else {
current.u_decommissioned = '';
}


})(current, previous);

This is perfect as I too thought a business rule would do the trick. Thanks!

Where I can find this BR?

Consider using GlideDateTime() instead of the deprecated gs.now() function.

 

//Get current time in UTC which is how all dates are stored in ServiceNow
var gdt = new GlideDateTime()
gs.info(gdt)