how can I force reset the passowrd after every 30 days

sunnysunny
Kilo Contributor

Can anyone please explain me in detail , I couldnot followed the wiki .

1 ACCEPTED SOLUTION

Sunny,



var gr = new GlideRecord('sys_user');


//The below query will reset the password for all users whose date of password is dated more than 20 days before.Change accordingly.


gr.addQuery('u_date_of_password','<','gs.daysAgo(-20))');


gr.query();


while (gr.next())


{


    gr.password_needs_reset = true;


    gr.update();


}


View solution in original post

16 REPLIES 16

Harneet Sital
Mega Sage
Mega Sage

Hi Sunny,



Here is how you can :


1. Goto System Definitions > Scheduled jobs


find_real_file.png


Select Automatically run a script of your choice.



2. In the run field select monthly and write the below script :


var gr = new GlideRecord('sys_user');


//The below query will reset the password for all users. You can add query as per your need here.


gr.query();


while (gr.next())


{


          gr.password_needs_reset = true;


    gr.update();


}



find_real_file.png


I thought about that at first also, but it resets everyone regardless, even if they just reset their own password yesterday. You need to keep track of the last time it was reset and only affect those people after 30 days.


Chuck,


Oh yes. I did not think of that scenario before. And yes the script-less scheduled job is really helpful when you are new to ServiceNow, this handles the scripted jobs like a charm. Thanks a lot for sharing.


Hi Harneet



As check mentioned I created datetime field on the user form and everytime the password changes, it will set the date time field to current value. For this all I created a business rule, but this business rule is not filling the datetime field with current value. Below is my business rule


(function executeRule(current, previous /*null when async*/) {




  ccur=current.getValue('user_password');


  cprev=previous.getValue('user_password');


  if (ccur!=cprev)


  {


  current.setValue('u_date_of_password',gs.nowDateTime());


  gs.addInfoMessage('hello');


  }





})(current, previous);