Hi All,I need to generate and set a random password for the selected user.Can anyone help me on this?Thanks

kirti0604
Kilo Contributor

Hi All,I need to generate and set a random password for the selected user.Can anyone help me on this?Thanks

11 REPLIES 11

Harneet Sital
Mega Sage
Mega Sage

Hi Rishi,



On the user table, Use math.random() function available with Javascript. Follow : Random Number Generator


To set the value to the password field, use the setValue() function available in the Glide Record API.



Let me know if you need any more help on this.


Mihir Mohanta
Kilo Sage

Hi Rishi,


Try below script.This will generate a random string of 8 characters.You can use it in both business rule or client script.


Try below script inside a client script and see the alert.



var string_length = 8;


              var randomstring = '';


              for (var i=0; i<string_length; i++) {


                     


  randomstring = Math.random().toString(36).slice(-8);


              }


  alert(randomstring);





Thanks,


Mihir


thanks Mihir,it's working good...


There is one more field "         Password valid till"-this should show the endtime duration.For eg: if a user selects the validity of 4 hours then the"Password valid till" field should show the time   of 4 hours later from now.Can u help on this too.I am a beginner.


Thanks!


gs.hoursAgo(integer)   function calculate the time by hours from current time.



Please go through below link for your reference



GlideSystem Date and Time Functions - ServiceNow Wiki



It is a server sided function.


So you can do it by using business rule or by using Glide ajax in client script.




Thanks,


Mihir