Article - Employee Offboarding Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hello Community,
Recently, I had a chance to implement something that I feel is quite helpful for managers in tracking pending items when a user leaves an organization.
Whenever a user is offboarded from an organization or in ServiceNow terminologies when a user is marked inactive in servicenow , there's often a gap between the direct manager of the user to understand the pending action items user had before he/she was terminated.
Many times , these tasks /approvals/ group memberships remain unnoticed which may cause complaince issues.
This notification contains a summary of all the pending tasks/approvals for the user. Hence, manager can take an account of those tasks and reassign it to the other team members.
Notification Example -
Configurations done to achieve this -
1. Business Rule (to trigger the event and to check if the user gets active false)
After update
Condition - Active changes to False
Table - Sys_user
Script -
(function executeRule(current, previous /*null when async*/ ) {
var parm1 = current.sys_id;
if (previous.active && !current.active && current.manager) {
var taskGR = new GlideRecord('task');
taskGR.addQuery('assigned_to', current.sys_id);
taskGR.addActiveQuery();
taskGR.query();
if (taskGR.next()) {
gs.eventQueue("user.inactive.pending.tasks", current, parm1, current.manager);
}
var approvalGr = new GlideRecord('sysapproval_approver');
approvalGr.addQuery('approver', current.sys_id);
approvalGr.addEncodedQuery('state=requested');
approvalGr.query();
if(approvalGr.next()){
gs.eventQueue("user.inactive.pending.approvals",current,parm1,current.manager);
}
}
})(current, previous);
2. Email Script (to form the table , add the link )
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
// Add your code here
var user = current.assigned_to;
var taskGR = new GlideRecord('task');
taskGR.addQuery('assigned_to', event.parm1);
taskGR.addQuery('active', true);
taskGR.query();
if (!taskGR.hasNext()) {
template.print("No active tasks assigned to this inactive user.");
return;
}
template.print("<table border='1' cellpadding='5' cellspacing='0'>");
template.print("<tr><th>Task Number</th><th>Short Description</th><th>Link</th></tr>");
while (taskGR.next()) {
var taskNumber = taskGR.getDisplayValue('number');
var shortDesc = taskGR.getDisplayValue('short_description');
var link = gs.getProperty('glide.servlet.uri') + taskGR.getLink(true);
template.print("<tr>");
template.print("<td>" + taskNumber + "</td>");
template.print("<td>" + shortDesc + "</td>");
template.print("<td><a href='" + link + "'>View</a></td>");
template.print("</tr>");
}
template.print("</table>");
})(current, template, email, email_action, event);
3. Finally the notification to trigger the event , and add the body content that you want.
Table - sys_user
Send - Event is triggered
Subject - Subject of your email
Message - Summary of your email.
Found this useful? Don’t forget to mark it helpful and share it with your colleagues.
Regards,
Nayan