- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
How can I write a ServiceNow script to check whether incidents are assigned to active users, and if the assigned user is inactive, automatically reassign the incident to that user’s manager? If the manager is also inactive, how can the script continue moving up the management hierarchy (up to four levels) until it finds an active manager to assign the incident to?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @NegiSNOW
You can create scheduled job script and apply below script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @NegiSNOW !!
You can achieve this using a Before Business Rule on the Incident table.
Table: Incident
When: Before
Insert: ✔
Update: ✔
(Optional condition: Assigned To changes)
(function executeRule(current, previous) {
if (!current.assigned_to) {
return;
}
var userGR = new GlideRecord('sys_user');
if (!userGR.get(current.assigned_to)) {
return;
}
// If assigned user is active, no action needed
if (userGR.active) {
return;
}
var manager = userGR.manager;
var level = 0;
var maxLevels = 4;
while (manager && level < maxLevels) {
var managerGR = new GlideRecord('sys_user');
if (!managerGR.get(manager)) {
break;
}
if (managerGR.active) {
current.assigned_to = managerGR.sys_id;
break;
}
manager = managerGR.manager;
level++;
}
})(current, previous);
Mark this as Helpful if it clarifies the issue.
Accept the solution if this answers your question.
Regards,
Vaishnavi
Associate Technical Consultant
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi NegiSNOW,
You can write an after/update business rule on user table . Do recursive call to continue moving up management hierarchy. This is just a sample code. (not tested)
condition: active changes to false
Script:
function activeAssignedTo(current.sys_id);
var count =0;
function activeAssignedTo (UserID)
{
var gr = new GlideRecord('incident');
gr.addQuery('active', true);
gr.addQuery('assigned_to.sys_id', ''+UserID);
gr.setWorkflow(false);//use it if you do not need any other BRs to trigger
gr.query();
while(gr.next())
{
if (current.manager.active && count <4){
gr.assigned_to=current.manager;
gr.update();}
else
{
activeAssignedTo(current.manager);
count= count+1;
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @NegiSNOW
You can create scheduled job script and apply below script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @NegiSNOW !!
You can achieve this using a Before Business Rule on the Incident table.
Table: Incident
When: Before
Insert: ✔
Update: ✔
(Optional condition: Assigned To changes)
(function executeRule(current, previous) {
if (!current.assigned_to) {
return;
}
var userGR = new GlideRecord('sys_user');
if (!userGR.get(current.assigned_to)) {
return;
}
// If assigned user is active, no action needed
if (userGR.active) {
return;
}
var manager = userGR.manager;
var level = 0;
var maxLevels = 4;
while (manager && level < maxLevels) {
var managerGR = new GlideRecord('sys_user');
if (!managerGR.get(manager)) {
break;
}
if (managerGR.active) {
current.assigned_to = managerGR.sys_id;
break;
}
manager = managerGR.manager;
level++;
}
})(current, previous);
Mark this as Helpful if it clarifies the issue.
Accept the solution if this answers your question.
Regards,
Vaishnavi
Associate Technical Consultant

