How to activate the user in user table(sys_user) by using background script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2023 12:30 AM
How to activate the user in user table(sys_user) by using background script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2023 01:06 AM - edited ‎01-17-2023 01:07 AM
Hi @siri27 ,
Sample Script :-
// Query the sys_user table for all inactive users
var gr = new GlideRecord('sys_user');
gr.addQuery('active', false);
gr.query();
// Activate each user in the query result
while (gr.next()) {
gr.active = true;
gr.update();
}
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2023 01:17 AM
Hello @siri27 ,
you can try this script
var gr = new GlideRecord('sys_user');
gr.addQuery('active', false);
gr.addQuery('sys_id','your_user_record_sys_id');
gr.query();
if (gr.next()) {
gr.active = true;
gr.update();
}
if there are multiple users you can use this script
var gr = new GlideRecord('sys_user');
gr.addQuery('active', false);
gr.query();
while (gr.next()) {
gr.active = true;
gr.update();
}
Hope this helps
Mark my answer correct if this helps you
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2023 01:41 AM
Hi,
I'd echo the previous two suggestions, i.e. use a GildeRecord update, to set the sys_user.active field to true.
Just to be sure, you may also want to check/set the Locked Out field: sys_user.locked_out which should be set to false, given that the user will be unable to log in if active == true and locked_out == true
HTH,matt