Hi All,I need to generate and set a random password for the selected user.Can anyone help me on this?Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2016 03:10 AM
Hi All,I need to generate and set a random password for the selected user.Can anyone help me on this?Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2016 03:49 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2016 03:56 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2016 05:02 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2016 05:13 AM
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