- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2025 12:54 AM
We need to get the inactive users and reassigns all their associated Incidents, Problems, Tasks, and Change Tickets to active users within the same group. Could someone help me with this
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2025 06:37 AM
Hi @Swathi Gade
You can create a report on the TASK table with this condition, which will return all records where the assignment is inactive (active = false). You can use these records as a basis and manually assign them to the same group.
You can add filter task type = Change or Problem or Incident
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2025 06:57 AM
something like this in scheduled job or background script
But please test in DEV and then only migrate to next instance
(function() {
// Query inactive users
var inactiveUsers = new GlideRecord('sys_user');
inactiveUsers.addQuery('active', false);
inactiveUsers.query();
while (inactiveUsers.next()) {
var userId = inactiveUsers.sys_id;
var userGroup = inactiveUsers.getValue('sys_user_group'); // Assuming the user has a group field
// Query all active users in the same group
var activeUsers = new GlideRecord('sys_user');
activeUsers.addQuery('active', true);
activeUsers.addQuery('sys_user_group', userGroup);
activeUsers.query();
if (activeUsers.next()) {
var newAssignee = activeUsers.sys_id;
// Reassign Incidents
reassignRecords('incident', userId, newAssignee);
// Reassign Problems
reassignRecords('problem', userId, newAssignee);
// Reassign Tasks
reassignRecords('task', userId, newAssignee);
// Reassign Change Tickets
reassignRecords('change_request', userId, newAssignee);
}
}
function reassignRecords(tableName, oldAssignee, newAssignee) {
var gr = new GlideRecord(tableName);
gr.addQuery('assigned_to', oldAssignee);
gr.addQuery('active', true); // Only reassign active records
gr.query();
while (gr.next()) {
gr.assigned_to = newAssignee;
gr.update();
}
}
})();
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2025 06:37 AM
Hi @Swathi Gade
You can create a report on the TASK table with this condition, which will return all records where the assignment is inactive (active = false). You can use these records as a basis and manually assign them to the same group.
You can add filter task type = Change or Problem or Incident
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2025 06:57 AM
something like this in scheduled job or background script
But please test in DEV and then only migrate to next instance
(function() {
// Query inactive users
var inactiveUsers = new GlideRecord('sys_user');
inactiveUsers.addQuery('active', false);
inactiveUsers.query();
while (inactiveUsers.next()) {
var userId = inactiveUsers.sys_id;
var userGroup = inactiveUsers.getValue('sys_user_group'); // Assuming the user has a group field
// Query all active users in the same group
var activeUsers = new GlideRecord('sys_user');
activeUsers.addQuery('active', true);
activeUsers.addQuery('sys_user_group', userGroup);
activeUsers.query();
if (activeUsers.next()) {
var newAssignee = activeUsers.sys_id;
// Reassign Incidents
reassignRecords('incident', userId, newAssignee);
// Reassign Problems
reassignRecords('problem', userId, newAssignee);
// Reassign Tasks
reassignRecords('task', userId, newAssignee);
// Reassign Change Tickets
reassignRecords('change_request', userId, newAssignee);
}
}
function reassignRecords(tableName, oldAssignee, newAssignee) {
var gr = new GlideRecord(tableName);
gr.addQuery('assigned_to', oldAssignee);
gr.addQuery('active', true); // Only reassign active records
gr.query();
while (gr.next()) {
gr.assigned_to = newAssignee;
gr.update();
}
}
})();
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader