The CreatorCon Call for Content is officially open! Get started here.

Deactivate inactive user who is not login from last 3 month.

Nitin30
Kilo Contributor

A schedule job exists that runs daily at midnight that checks for the last login date of all users with an entitlement role [itil, sn_customerservice_agent, ITBM roles].  If the login date is more than 3 months ago, or if the created date was more than 3 months ago AND last login date is null, remove that user from the groups that are granting them the inherited roles.

Send a notification to any of these groups' manager that they have been removed due to inactivity.  Include the user name, email address, and last login date in this email.

 created the scheduled job  record is delete from group member table but notification is not triggering  the group member. But when i removed the deleteRecord() from the script notification is triggering.  

Please suggest what needs to do for both action will perform at some time gap.

var inactive = GlideRecord("sys_user");
inactive.addEncodedQuery("roles=ITIL^last_login_time<javascript:gs.beginningOfLast3Months()");
inactive.query();
while (inactive.next()) {

var user = GlideRecord("sys_user_grmember");
user.addQuery("user", inactive.sys_id);
user.query();
while (user.next()) {
gs.eventQueue('Testinggroup', user, user.group.manager);
user.deleteRecord();


}
}

Thanks in advanced.

1 ACCEPTED SOLUTION

Willem
Giga Sage
Giga Sage

Hi Nitin,

 

You are deleting the record that you send to the Event queue.

Perhaps you can change it to instead of sending user (which is a sys_user_grmember you are deleting) change it to the sys_user?

Make sure to check on which table your notification is as well and update accordingly.

 

Like this:

var inactive = GlideRecord("sys_user");
inactive.addEncodedQuery("roles=ITIL^last_login_time<javascript:gs.beginningOfLast3Months()");
inactive.query();
while (inactive.next()) {

    var user = GlideRecord("sys_user_grmember");
    user.addQuery("user", inactive.sys_id);
    user.query();
    while (user.next()) {
        gs.eventQueue('Testinggroup', inactive, user.group.manager);
        user.deleteRecord();
    }
}

View solution in original post

5 REPLIES 5

The SN Nerd
Giga Sage
Giga Sage

This is a good Use Case for Flow Designer.


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022