The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Populating a default password for users imported through excel file

Rain Vaine
Kilo Sage

Hello experts,

 

I have read in some documentations that we can use the run script option of the transform map to create or populate a field not included in the excel file. Is it also possible to the password field of the user table? If so, do you have idea on how to do it and the script to make it?

 

Thanks and Regards,

Vaine

1 ACCEPTED SOLUTION

@Rain Vaine try this

 

Setting the password field value through a transform row script is not recommended as the password field is encrypted and requires specific functions to set its value. Instead, it is recommended to use the default_password system property to set the default password value for new users.

Here's an example of how to set the default_password property:

  1. Navigate to System Properties > System.
  2. Search for the glide.security.default_password property.
  3. Set the value of this property to the desired default password.
  4. Save the property.

Now, whenever a new user is created, the default password will be set automatically.

Best practices for importing users from an Excel sheet include:

  1. Use a transform map to map the fields from the Excel sheet to the user table.
  2. Use the setPassword() function provided by the GlideRecord API to set the password value for each user.

Here's an example of a transform row script that imports users from an Excel sheet and sets their password:

(function transformRow(source, target, map, log, targetImportSetRow /*undefined on insert*/) {

  // Import fields from Excel sheet using source object
  target.setValue('first_name', source.first_name);
  target.setValue('last_name', source.last_name);
  target.setValue('email', source.email);

  // Set default password for new users
  var defaultPassword = gs.getProperty('glide.security.default_password');
  target.setPassword(defaultPassword);

})(source, target, map, log, targetImportSetRow);

 

View solution in original post

5 REPLIES 5

DUGGI
Giga Guru

In ServiceNow, it is not recommended to populate default passwords for users imported through an Excel file. This is because passwords should be kept secure and users should be required to set their own passwords for security reasons.

Instead, it is recommended to use a self-service password reset tool or integrate ServiceNow with an external identity provider such as Active Directory or LDAP to synchronize passwords.

If you still need to populate default passwords for users imported through an Excel file, you can do so by creating a Business Rule or a Scripted Import Set Transform that sets the password field for each imported user record.

Here is an example Business Rule script that sets a default password for new users:

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

  // Set the default password for new users
  if (current.isNewRecord()) {
    current.password.setDisplayValue('defaultpassword');
  }

})(current, previous);

In this example, the default password is set to "defaultpassword". You should modify the script to use a secure password that meets your organization's password policy requirements.

 

Note that it is recommended to use a secure method for password management, and default passwords should be avoided whenever possible for security reasons.

Actually what we want is so that the we don't have to set the password for each user individually. we would just instruct them to reset their password

How about if we were to put this to transform map script? How do we go about that?

 

Thanks

Rain Vaine
Kilo Sage

hello,
I tried using the transform map script function for the password and user id, for the user id it is working as expected, but for the password it is not. Below is the sample of my trial script.

RainVaine_0-1681344532758.png

Thanks and regards

Vaine

 

@Rain Vaine try this

 

Setting the password field value through a transform row script is not recommended as the password field is encrypted and requires specific functions to set its value. Instead, it is recommended to use the default_password system property to set the default password value for new users.

Here's an example of how to set the default_password property:

  1. Navigate to System Properties > System.
  2. Search for the glide.security.default_password property.
  3. Set the value of this property to the desired default password.
  4. Save the property.

Now, whenever a new user is created, the default password will be set automatically.

Best practices for importing users from an Excel sheet include:

  1. Use a transform map to map the fields from the Excel sheet to the user table.
  2. Use the setPassword() function provided by the GlideRecord API to set the password value for each user.

Here's an example of a transform row script that imports users from an Excel sheet and sets their password:

(function transformRow(source, target, map, log, targetImportSetRow /*undefined on insert*/) {

  // Import fields from Excel sheet using source object
  target.setValue('first_name', source.first_name);
  target.setValue('last_name', source.last_name);
  target.setValue('email', source.email);

  // Set default password for new users
  var defaultPassword = gs.getProperty('glide.security.default_password');
  target.setPassword(defaultPassword);

})(source, target, map, log, targetImportSetRow);