- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2025 01:23 AM
Hi,
I have attached system log, the business rule fetching CI sys id and current user id(from user table).
event triggered, script action. but the script execution failed into the line indexof. index value printing -1 still though it has value. kindly let me know the correction in the script:
Business Rule:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2025 05:26 AM
function deactivateuser(id, username) {
var gr = new GlideRecord("cmdb_ci");
gr.addQuery('sys_id', id);
gr.query();
while (gr.next()) {
var approver = gr.getValue('u_level_1_approver');
if (!approver) continue; // Safeguard for empty fields
var approverarray = approver.split(',').map(function(item) {
return item.trim().toLowerCase();
});
username = username.trim().toLowerCase();
gs.log("Approver Array: " + approverarray);
gs.log("Username: " + username);
var index = approverarray.indexOf(username);
gs.log("Index: " + index);
if (index !== -1) {
approverarray.splice(index, 1);
gr.setValue('u_level_1_approver', approverarray.join(',')); // Convert back to string
gr.update();
gs.log("Updated Approver Array: " + approverarray);
}
}
}
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 12:55 AM
Thank you for marking my response as helpful.
As pew new community feature you can mark multiple responses as correct.
If my response helped please mark it correct as well so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader