How to pass user in eventQueue

Preethi26
Tera Contributor

Hi Team,

I am trying to schedule a job that remove users groups and roles who have not logged in for last 3 months.

But while working on notification im stuck as its new for me.

I have gave admin directly in user field of notification in this case its  sending notification for admin but not for specific users  for whom role/group is deleted.

Kindly correct me.

Preethi26_0-1701264133561.png

Preethi26_1-1701264389460.png

 

 

11 REPLIES 11

Anil Lande
Kilo Patron

Hi,

Can you please share your script as a text/code, it is diffucult to suggest changes in screenshot.

Also I see you are setting user record active=false; 

System does not send notifications to inactive users, user should be active in order to receive email notifications.

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('active=true^last_loginRELATIVELT@dayofweek@ago@90'); // this gets all the users who are active and last logged in 3 months(90) ago
gr.query();
while (gr.next()) {
    gr.active = 'false';
    gr.update();
    var gr2 = new GlideRecord('sys_user_grmember');
    gr2.addQuery('user', gr.sys_id);
    gr2.query();
    gr2.deleteMultiple(); //deletes the user from the groups
    var gr1 = new GlideRecord('sys_user_has_role');
    gr1.addQuery('user', gr.sys_id);
    gr1.query();
    gr1.deleteMultiple(); // deletes all the roles the user have
    gs.eventQueue('notify user',current, current.user_name , current.user_name);
}

Hi,

Please try below:

 

var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('active=true^last_loginRELATIVELT@dayofweek@ago@90'); // this gets all the users who are active and last logged in 3 months(90) ago
gr.query();
while (gr.next()) {
//Moving bewlo two lines to end of script
    //gr.active = 'false';
    //gr.update();
    var gr2 = new GlideRecord('sys_user_grmember');
    gr2.addQuery('user', gr.sys_id);
    gr2.query();
    gr2.deleteMultiple(); //deletes the user from the groups
    var gr1 = new GlideRecord('sys_user_has_role');
    gr1.addQuery('user', gr.sys_id);
    gr1.query();
    gr1.deleteMultiple(); // deletes all the roles the user have
    gs.eventQueue('notify user',gr, gr.email , gr.name);

Once your trigger event make user record inactive , i would suggest this is not required
  gr.active = 'false';
    gr.update();
}

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

@Preethi26 did you check this script?

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande