Mass migration of users through a flow

tomaslindev
Mega Guru

Hi everyone,

I need your help to reset the password of several users under certain conditions, for this I have created a flow that will be executed only once and I have used the “Update password” action, using the script section of the action I have added the following script to create an encrypted password formed by the first and last name of the user plus a random number, and then add the password to the body of an email to send to each user. The flow returns this error “Error: password must not be empty (sys_script_include.c2bb80aa73126300039a2ea3c4f6a721.script; line 20)”. Any ideas?
Thank you very much and best regards.

 

Flow Migración.png

 

(function execute(inputs, outputs) {
    
    var first_name = inputs.first_name; 
    var last_name = inputs.last_name;

    var randomNumber = Math.floor(Math.random() * 1000);

    var password = first_name + last_name + randomNumber;

    var encr = new GlideEncrypter();
    var encryptedPassword = encr.encrypt(password);

    outputs.encryptedPassword = encryptedPassword;

    gs.info('First name: ' + first_name);
    gs.info('Last name: ' + last_name);
    gs.info('Generated password: ' + password);
    gs.info('Encrypted password: ' + encryptedPassword);

})(inputs, outputs);

 

1 ACCEPTED SOLUTION

fidel_ey
Tera Guru

Hi Tomas.

 

I tried in a Background script , its something like this. But I am not convinced of the way in which you are proposing, as it may incur in error, but if it is as indicated I recommend that you pass in an email the password if the user to avoid sending confidential information.

var first_name = "John";
var last_name = "Doe";

var randomNumber = Math.floor(Math.random() * 1000);

var password = first_name + last_name + randomNumber;

if (!password) {
    throw new Error('Generated password cannot be empty.');
}

var encr = new GlideEncrypter();
var encryptedPassword = encr.encrypt(password);

if (!encryptedPassword) {
    throw new Error('Encryption failed. Encrypted password is empty.');
}

gs.info('First name: ' + first_name);
gs.info('Last name: ' + last_name);
gs.info('Generated password: ' + password);
gs.info('Encrypted password: ' + encryptedPassword);
*** Script: First name: John
*** Script: Last name: Doe
*** Script: Generated password: JohnDoe991
*** Script: Encrypted password: KNXvgcvr3QBKrGjyHNEceg==
 

View solution in original post

10 REPLIES 10

Thank you very much for the help, I'm going to create a new action and give it this new approach to see if I can hopefully solve the problem; although I don't know exactly how to do it with this new process.

@tomaslindev 

do keep us posted on this.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I have created a new action to encapsulate the script as done in the post you attached, I am currently at this point doing tests.

Migración AD 1.pngMigración AD 2.png

fidel_ey
Tera Guru

Hi Tomas.

 

I tried in a Background script , its something like this. But I am not convinced of the way in which you are proposing, as it may incur in error, but if it is as indicated I recommend that you pass in an email the password if the user to avoid sending confidential information.

var first_name = "John";
var last_name = "Doe";

var randomNumber = Math.floor(Math.random() * 1000);

var password = first_name + last_name + randomNumber;

if (!password) {
    throw new Error('Generated password cannot be empty.');
}

var encr = new GlideEncrypter();
var encryptedPassword = encr.encrypt(password);

if (!encryptedPassword) {
    throw new Error('Encryption failed. Encrypted password is empty.');
}

gs.info('First name: ' + first_name);
gs.info('Last name: ' + last_name);
gs.info('Generated password: ' + password);
gs.info('Encrypted password: ' + encryptedPassword);
*** Script: First name: John
*** Script: Last name: Doe
*** Script: Generated password: JohnDoe991
*** Script: Encrypted password: KNXvgcvr3QBKrGjyHNEceg==
 

Thank you very much for your help.
This flow is intended to reset the passwords of specific users indicated in the flow trigger and then send these new passwords to each user via email. Why don't you agree with the proposed idea?
Regards.