- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2024 02:31 AM - edited 11-04-2024 02:33 AM
Hi All,
We have a schedule job which should give us the users who are part of the particular group and have not logged in for 2 months,so we need to send an email to users 1 week prior to the removal.
Here is my script, and event,but event is not working.Event is ion sys_user table.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2024 03:14 AM
Hi,
You can improve the performance of this script by using a subquery and avoid the need for nested GlideRecord queries which are resource intensive.
(function() {
var LAST_LOGIN_DAYS_PRIOR = 54;
var USER_GROUP_ID = 'sys_id_of_group_here';
var users = [];
var applicableUsersGR = new GlideRecord('sys_user');
applicableUsersGR.addQuery('sys_class_name' , 'sys_user');
applicableUsersGR.addActiveQuery();
applicableUsersGR.addQuery('last_login_time' , 'RELATIVELT' , gs.daysAgo(LAST_LOGIN_DAYS_PRIOR)); //Not logged in prior to the date limit const
applicableUsersGR.addEncodedQuery('RLQUERYsys_user_grmember.user,>=1,m2m^group=' + USER_GROUP_ID + '^ENDRLQUERY'); //RL query to onl pull users who are a member of the desired group;
applicableUsersGR.query();
while(applicableUsersGR.next()){
users.push({
'user' : applicableUsersGR.getUniqueValue(),
'email' : applicableUsersGR.getValue('email')
});
}
gs.eventQueue('notify_users' , applicableUsersGR, JSON.stringify(users));
})()
Note, the second parameter of gs.eventQueue needs to be a gliderecord value

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2024 03:14 AM
Hi,
You can improve the performance of this script by using a subquery and avoid the need for nested GlideRecord queries which are resource intensive.
(function() {
var LAST_LOGIN_DAYS_PRIOR = 54;
var USER_GROUP_ID = 'sys_id_of_group_here';
var users = [];
var applicableUsersGR = new GlideRecord('sys_user');
applicableUsersGR.addQuery('sys_class_name' , 'sys_user');
applicableUsersGR.addActiveQuery();
applicableUsersGR.addQuery('last_login_time' , 'RELATIVELT' , gs.daysAgo(LAST_LOGIN_DAYS_PRIOR)); //Not logged in prior to the date limit const
applicableUsersGR.addEncodedQuery('RLQUERYsys_user_grmember.user,>=1,m2m^group=' + USER_GROUP_ID + '^ENDRLQUERY'); //RL query to onl pull users who are a member of the desired group;
applicableUsersGR.query();
while(applicableUsersGR.next()){
users.push({
'user' : applicableUsersGR.getUniqueValue(),
'email' : applicableUsersGR.getValue('email')
});
}
gs.eventQueue('notify_users' , applicableUsersGR, JSON.stringify(users));
})()
Note, the second parameter of gs.eventQueue needs to be a gliderecord value