Need to remove a user from specific group if users not logged in 30 days But those group need to call from sys_properties
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2022 06:57 AM
Hi All,
Need to remove a user from specific group if users not logged in 3o days.
Ex : I have group called ( ITSM_Group ) in that group we have multiple users, If any user not logged in more than 30days we need to remove the user from the group.
But we need to create a property for the group and then we need to call that property through SCHEDULED job and then it looks the lost login user on group and it removed the users from group.
Please suggest, How can i create property for the groups and how to call the property through SCHEDULED job
Thanks ALL,
- Labels:
-
Incident Management
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2022 10:34 AM
Hi,
First Create a System property by typing -->sys_properties.LIST in filter navigator ---> Create New-->Assuming you create a system property with name -- "login_limit_date"
Then Create a Scheduled Job like this -
//Sys ID of the group which will contain sys_id of the group
var group_sys_id=gs.getProperty("group_sys_id_propety");
var gr= new GlideRecord('sys_user_grmember');
gr.addQuery('group','group_sys_id');
gr.query();
while(gr.next()){
var last_login_date=new GlideDateTime(gr.user.last_login);
var now=new GlideDateTime();
//This calculates the difference between last login date of a user and now. For example if a user logged in 25 days back, it will return -25
var diff=GlideDateTime.subtract(now,last_login_date);
//System property which contain the login limit data. For example, if you want to deactivate the user after 30 days, you will enter 30 here
var login_limit_date=gs.getProperty('login_limit_date')
//Since diff contains negative value, multiplying it with (-1)
if(((diff.getRoundedDayPart()*-1) > login_limit_date)){
var days=(diff.getRoundedDayPart()*-1);
var grUsr= new GlideRecord('sys_user');
grUsr.get(gr.user);
grUsr.active=false;
grUsr.update();
}
Please upvote or Mark as Correct if you found this useful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2022 11:08 AM
Hi Anurag,
Thanks for reply, Below is your code.
Below we have provide sys id of group But my scenario i need to create a sys Property for Groups only, in that property only i need to call the group. is it possible?
In this line
var login_limit_date=gs.getProperty('login_limit_date')
we call property i didt get which property it is, its stored date?
var gr= new GlideRecord('sys_user_grmember');
gr.addQuery('group','d13f2e6ddb304b00ac825478dc961940')------------- > Cant we use this group in property will crate proprty for groups
gr.query();
while(gr.next()){
var last_login_date=new GlideDateTime(gr.user.last_login);
var now=new GlideDateTime();
var diff=GlideDateTime.subtract(now,last_login_date);
var login_limit_date=gs.getProperty('login_limit_date') --------- > could you please explain about this Property for what we need create this login_limit_date
if(((diff.getRoundedDayPart()*-1) > login_limit_date)){ --------------- here it how it calculate 30days
var days=(diff.getRoundedDayPart()*-1);
var grUsr= new GlideRecord('sys_user');
grUsr.get(gr.user);
grUsr.active=false;
grUsr.update(); ------------------- where is removes the users from group
}
Please suggest,
Thanks,
Varma

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2022 11:11 AM
Hi Varma,
I have updated my answer above. Please check and mark it as correct if you found this useful.
Thanks and Regards,
Anurag Mishra