Auto Populating Configuration Item with Business Rules
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2024 02:25 AM
Hi ServiceNow Community,
I’m working on a script to automate the population of the configuration item (CI) field in incidents generated by Applications Manager. The goal is to extract the CI from the short description of the incident. The short description always starts with 'BRV' and ends with a number (e.g., "BRVMSLDB2305"). My script is triggered when the incident state is 'new', and it should set the CI based on the extracted value.
Here’s the progress I’ve made:
- Script Logic: I’ve written a business rule script to extract the CI from the short description and set it in the CI field.
- Log Confirmation: The logs show that the business rule is being triggered and executing:
- Business rule triggered for record: bINC0530159
- Setting CI in record: BRVMSLDB2305
- Found configuration item: BRVMSLDB2305
- Testing: The log entries confirm that the business rule is running, and the CI seems to be extracted correctly.
However, despite the script running without errors, the CI field is not being populated in the incident record. The logs do not show any errors or warnings that could indicate a problem. Everything appears fine from the log perspective.
Steps I’ve Taken to Troubleshoot:
- Verified that the CI being extracted from the short description exists in the CMDB.
- Checked the business rule execution, which seems to be functioning correctly as per the logs.
- Ensured there are no ACL or permission issues that could prevent the CI field from being updated.
I’m unsure if there’s something I might be missing. Could there be any additional considerations or hidden restrictions in ServiceNow that might prevent the CI field from being set, even though the script appears to run successfully?
Any guidance or suggestions on what to check next would be greatly appreciated!
Thanks in advance!
Alarm short desciption - Alarm from the Applications Manager Critical brvmsldb2305.acli.bvapps.com !!! PLEASE DO NOT CLOSE MANUALLY !!! - [ Health of BRVMSLDB2305_MSSQL is Critical ]
from this I'm extracting the CI BRVMSLDB2305 and i want this to be in configuration item.
condition - current.short_description.indexOf('Alarm from the Applications Manager') >= 0
script
(function executeRule(current, previous /*null when async*/) {
// Check if the business rule is triggered
gs.log("Business rule triggered for record: " + current.number);
// Capture the short description
var shortDesc = current.short_description;
gs.log("Short description: " + shortDesc);
// Regular expression to find the CI
var ciRegex = /BRV[A-Z0-9]+[0-9]+/;
var match = shortDesc.match(ciRegex);
// Check if the CI is found in the short description
if (match) {
var configurationItem = match[0];
gs.log("Found configuration item: " + configurationItem);
// Set the CI field (cmdb_ci)
current.cmdb_ci = configurationItem;
gs.log("Setting CI in record: " + current.cmdb_ci);
} else {
gs.log("No configuration item found in short description.");
}
})(current, previous);