- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2022 11:00 AM
Any suggestions on how the operational status can change from Non-Operational to Operational if the CI gets re-discovered?
Solved! Go to Solution.
- Labels:
-
Discovery

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2022 11:58 AM
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2022 11:58 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2022 12:00 PM
This is perfect as I too thought a business rule would do the trick. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2024 01:51 AM
Where I can find this BR?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2024 04:20 AM
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)