After update Business Rule for Operational Status when Install Status was changes into 'Absent' due to the Discovery Deletion Strategy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2019 07:27 PM
Hi I'm new to ServiceNow and not really good at coding. We're are currently using Kingston and wondering if it's possible to create an after update business rule that would automatically change the operational status of a CI into 'Non-Operational' when the Install Status was changed into 'Absent' due to the Discovery Pattern Deletion Strategy set?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2019 07:34 PM
Hi,
This can be done with no coding at all like so:
Create after business rule on update for the cmdb_ci table
Then on the actions tab set:
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2019 04:45 PM
I tried doing exactly what was on the images above but when I tested it, it didn't change the operational status into "Non-Operational".
I look through some Business Rules we have and found something that I assume, syncs the Install Status and Operational Status. When Operational Status is changed into 'Retired', the Install Status changes into 'Retired' as well. I wonder if this can be modified into something I needed?
var OpsStatusSynchronizer = Class.create();
OpsStatusSynchronizer.prototype = {
initialize: function(currentCIRecord) {
if (!currentCIRecord)
return;
this.current = currentCIRecord;
if (currentCIRecord.getElement('hardware_status')) {
this.statusField = 'hardware_status';
this.baseTable = 'cmdb_ci_hardware';
} else {
this.statusField = 'install_status';
this.baseTable = 'cmdb_ci';
}
},
shouldSync: function() {
if (!this.current)
return false;
var current = this.current;
var opsChoice = current.getElement('operational_status').getChoiceValue();
var statusChoice = current.getElement(this.statusField).getChoiceValue();
return opsChoice == 'Retired' && statusChoice != 'Retired' ||
opsChoice != 'Retired' && statusChoice == 'Retired';
},
syncStatus: function() {
if (!this.current)
return;
var current = this.current;
var statusField = this.statusField;
var baseTable = this.baseTable;
var fromOps = {
'Retired': 'Retired'
};
var toOps = {
'Retired': 'Retired'
};
var ops = current.getElement('operational_status');
var status = current.getElement(statusField);
if (ops.changes()) { // higher priority for checking Operational Status
var opsChoice = ops.getChoiceValue();
var statusChoice = fromOps[opsChoice];
var subStatusChoice = ''; // necessary to set Hardware Asset retired
if (!statusChoice) {
statusChoice = 'Installed';
subStatusChoice = 'In Use';
}
current.setValue(statusField,
new GlideChoiceListGenerator(baseTable, statusField).get().getValueOf(statusChoice));
if (baseTable == 'cmdb_ci_hardware') {
var subStatusField = 'hardware_substatus';
current.setValue(subStatusField, !subStatusChoice ? '' :
new GlideChoiceListGenerator(baseTable, subStatusField).get().getValueOf(subStatusChoice));
}
current.update();
} else {
var statusChoice = status.getChoiceValue();
var opsChoice = toOps[statusChoice];
if (!opsChoice)
opsChoice = 'Non-Operational';
var registration = SNC.StateManagementScriptableApi.registerOperator();
var jsonUntil = new JSON();
var output = jsonUntil.decode(registration);
var requestorId = output.requestorId;
var sys_id = current.sys_id + '';
var setOpsState = SNC.StateManagementScriptableApi.setBulkCIOperationalState(requestorId, sys_id, opsChoice);
output = jsonUntil.decode(setOpsState);
if (!output.result)
gs.logError('Failed to update Operational Status via business rule', 'ci_state_management');
SNC.StateManagementScriptableApi.unregisterOperator(requestorId);
}
},
type: 'OpsStatusSynchronizer'
};
var synchronizer = new OpsStatusSynchronizer(current);
if (synchronizer.shouldSync())
synchronizer.syncStatus();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2019 04:44 PM
I tried doing exactly what was on the images above but when I tested it, it didn't change the operational status into "Non-Operational".
I look through some Business Rules we have and found something that I assume, syncs the Install Status and Operational Status. When Operational Status is changed into 'Retired', the Install Status changes into 'Retired' as well. I wonder if this can be modified into something I needed?
var OpsStatusSynchronizer = Class.create();
OpsStatusSynchronizer.prototype = {
initialize: function(currentCIRecord) {
if (!currentCIRecord)
return;
this.current = currentCIRecord;
if (currentCIRecord.getElement('hardware_status')) {
this.statusField = 'hardware_status';
this.baseTable = 'cmdb_ci_hardware';
} else {
this.statusField = 'install_status';
this.baseTable = 'cmdb_ci';
}
},
shouldSync: function() {
if (!this.current)
return false;
var current = this.current;
var opsChoice = current.getElement('operational_status').getChoiceValue();
var statusChoice = current.getElement(this.statusField).getChoiceValue();
return opsChoice == 'Retired' && statusChoice != 'Retired' ||
opsChoice != 'Retired' && statusChoice == 'Retired';
},
syncStatus: function() {
if (!this.current)
return;
var current = this.current;
var statusField = this.statusField;
var baseTable = this.baseTable;
var fromOps = {
'Retired': 'Retired'
};
var toOps = {
'Retired': 'Retired'
};
var ops = current.getElement('operational_status');
var status = current.getElement(statusField);
if (ops.changes()) { // higher priority for checking Operational Status
var opsChoice = ops.getChoiceValue();
var statusChoice = fromOps[opsChoice];
var subStatusChoice = ''; // necessary to set Hardware Asset retired
if (!statusChoice) {
statusChoice = 'Installed';
subStatusChoice = 'In Use';
}
current.setValue(statusField,
new GlideChoiceListGenerator(baseTable, statusField).get().getValueOf(statusChoice));
if (baseTable == 'cmdb_ci_hardware') {
var subStatusField = 'hardware_substatus';
current.setValue(subStatusField, !subStatusChoice ? '' :
new GlideChoiceListGenerator(baseTable, subStatusField).get().getValueOf(subStatusChoice));
}
current.update();
} else {
var statusChoice = status.getChoiceValue();
var opsChoice = toOps[statusChoice];
if (!opsChoice)
opsChoice = 'Non-Operational';
var registration = SNC.StateManagementScriptableApi.registerOperator();
var jsonUntil = new JSON();
var output = jsonUntil.decode(registration);
var requestorId = output.requestorId;
var sys_id = current.sys_id + '';
var setOpsState = SNC.StateManagementScriptableApi.setBulkCIOperationalState(requestorId, sys_id, opsChoice);
output = jsonUntil.decode(setOpsState);
if (!output.result)
gs.logError('Failed to update Operational Status via business rule', 'ci_state_management');
SNC.StateManagementScriptableApi.unregisterOperator(requestorId);
}
},
type: 'OpsStatusSynchronizer'
};
var synchronizer = new OpsStatusSynchronizer(current);
if (synchronizer.shouldSync())
synchronizer.syncStatus();