Sending Email to Inactive user.

HaseemM85874654
Tera Contributor

 

I have implemented a scheduled job in ServiceNow to track and manage inactive users based on their last login time. This ensures that inactive users are properly monitored and notified before deactivation. However, the final notification is not being received by users when using the following query:

 

javascript
 
gs.eventQueue("user.inactive.60", grInactive); grInactive.addEncodedQuery("last_login_time<=" + date60);
 

Here, date60 is a GlideDate variable that retrieves all users who have not logged in for more than 60 days, and grInactive is a GlideRecord variable.

1 ACCEPTED SOLUTION

Here's my approach and it's working as expected.

1. Event registry: 

JSiva_0-1741411173658.png

 

2. Scheduled job:

JSiva_1-1741411221917.png

 

 

var user = new GlideRecord('sys_user');

//Active users with last login time is not empty and last login time is before 60 days.
user.addEncodedQuery("active=true^last_login_timeISNOTEMPTY^last_login_timeRELATIVELT@dayofweek@ago@60");

user.query();
while (user.next()) {

    //Triggering the event by passing the user record and user sys_id
    gs.eventQueue('dormancy.policy.trigger', user, user.sys_id);

    // Calling the function to remove user from the groups
    this.removeUsersFromGroup(user);
}

// Function to remove users from the group
function removeUsersFromGroup(user_record) {
    var group_membership = new GlideRecord('sys_user_grmember');
    group_membership.addQuery("user", user_record.sys_id);
    group_membership.deleteMultiple();
}

 

 

Notification:

JSiva_2-1741411430062.pngJSiva_3-1741411447299.pngJSiva_4-1741411471295.png

 

Result:

JSiva_5-1741411531988.pngJSiva_6-1741411555966.png

I hope this helps.

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@HaseemM85874654 

in your event Queue you should pass the 3rd parameter which is recipient

Ensure in notification Event parm1 contains Recipient = True

gs.eventQueue("user.inactive.60", grInactive, grInactive.email.toString());

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader