- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2025 12:33 PM
Hello!
I am trying to troubleshoot a custom script that should be assigning VITs to the group in the variable u_event_group. This script is assigning records that do not have this custom dictionary entry and/or the dictionary entry is empty. If anyone could review this script and identify potential bugs, I would greatly appreciate it.
Solved! Go to Solution.
- Labels:
-
CMDB
-
Vulnerability Response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2025 12:40 PM
Your script looks like fine, but there are a couple of areas that could lead to unexpected behavior, especially when you're checking for the u_event_group value
var gr = new GlideRecord('server');
var ciSID = current.sys_id;
gr.addQuery('sys_id', ciSID);
gr.query();
if (gr.getRowCount() > 0) {
gr.next(); // Make sure we're processing the first record
var eventGroup = gr.getValue('u_event_group');
if (eventGroup) {
current.assignment_group = eventGroup;
} else {
gs.log('No event group found for CI: ' + ciSID);
// Optionally handle case where no event group is found
}
} else {
gs.log('No server record found for CI: ' + ciSID);
// Optionally handle the case where no server record is found
}
- Added getRowCount() to check for multiple records and ensure you're only processing one.
- Simplified the check for an empty eventGroup by just using if (eventGroup).
- Added gs.log calls to provide visibility into the script's behavior.
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2025 12:40 PM
Your script looks like fine, but there are a couple of areas that could lead to unexpected behavior, especially when you're checking for the u_event_group value
var gr = new GlideRecord('server');
var ciSID = current.sys_id;
gr.addQuery('sys_id', ciSID);
gr.query();
if (gr.getRowCount() > 0) {
gr.next(); // Make sure we're processing the first record
var eventGroup = gr.getValue('u_event_group');
if (eventGroup) {
current.assignment_group = eventGroup;
} else {
gs.log('No event group found for CI: ' + ciSID);
// Optionally handle case where no event group is found
}
} else {
gs.log('No server record found for CI: ' + ciSID);
// Optionally handle the case where no server record is found
}
- Added getRowCount() to check for multiple records and ensure you're only processing one.
- Simplified the check for an empty eventGroup by just using if (eventGroup).
- Added gs.log calls to provide visibility into the script's behavior.
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.