- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2022 09:50 PM
Hi,
I have to set password reset policy for users having "AD user id" is empty and users who having "Admin" or "Security Admin" roles.
"Ad user id" is field in user record.
For archiving this, I have written scheduled job, Below the script.
Script:
var gr = new GlideRecord('sys_user');
gr.addQuery('u_password_last_changed', '>', 'gs.daysAgo(30))');
gr.query();
while (gr.next()) {
gr.password_needs_reset = true;
gr.update();
}
Here i need to build query, Can any one help on this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2022 10:01 PM
Hi,
update as this
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery("u_ad_user_idIEEMPTY"); // use correct field name
gr.addQuery('u_password_last_changed', '>', 'gs.daysAgo(30))');
gr.addEncodedQuery("roles=admin^ORroles=security_admin");
gr.query();
while (gr.next()) {
gr.password_needs_reset = true;
gr.update();
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2022 10:01 PM
Hi,
update as this
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery("u_ad_user_idIEEMPTY"); // use correct field name
gr.addQuery('u_password_last_changed', '>', 'gs.daysAgo(30))');
gr.addEncodedQuery("roles=admin^ORroles=security_admin");
gr.query();
while (gr.next()) {
gr.password_needs_reset = true;
gr.update();
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2022 11:43 PM
Hi
Thanks for reply,
I have added query for getting last password changed is 30 days is notworking,
"gr.addQuery('u_password_last_changed', '>', 'gs.daysAgo(30))');"
As per my requirement if Last password changed date is greater then 30 days then only i need to make true "Password reset" field.
Currently it is working like every day it is updating the Password reset check box field
Help me on this .
Thanks,
Prasad.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2022 11:44 PM
then update the query as this
gr.addEncodedQuery("u_password_last_changedRELATIVELT@dayofweek@ago@30");
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2022 11:43 PM
@prasad
Hi Prasad,
I could see you marked my response as correct earlier and now it is not.
Any reason for that?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader