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

4. last login more than 6month user need to set inactive in servicenow

keerthana
Tera Contributor

set inactive

4 REPLIES 4

Peter Bodelier
Giga Sage

You have multiple possibilities, but the easiest to create is a Daily Flow, which looks up the users who are eligible for inactivation, and sets all the fields needed.


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Koen Spiessens
Tera Contributor

Create a scheduled job to run daily:

var userGr = new GlideRecord('sys_user');
userGr.addEncodedQuery('last_login_time<javascript&colon;gs.beginningOfLast6Months()');
userGr.query();

// Iterate through the result set
while (userGr.next()) {
    userGR.active = false;
	userGR.update();
}

manjusha_
Kilo Sage

@keerthana 

 

1.You can use both scheduled job or flow designer to acieve your functionality .

2.As a best a best way you should use flow designer which will trigger on daily basis

3.You need to look up the user records who has not logged in since last 6 months  ,update those user records as inactive  

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact

Thanks,

Manjusha Bangale

Community Alums
Not applicable

Hello Keerthana,

You can create scheduled job by defining it to run daily or periodically

In script field we need to check for user who haven't logged in for more than 6 months
Script: 
(function() {

var sixMonthsAgo = new GlideDateTime();

sixMonthsAgo.subtract(180); // subtracts 180 days i.e 6 months
var userGr = new GlideRecord('sys_user');

userGr.addQuery('last_login<', sixMonthsAgo);

userGr.query();

while(userGr.next()) {

userGr.active = false;

userGr.update();

}

})();

 

Save the scheduled job

If you want to add additional logic or notification when a user is marked inactive, you can create a business rule 

set the table to sys_user and define condition and action you want to trigger when user's field active is set to false 

Save the business rule 

Activate the scheduled job