- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 05:18 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2023 06:15 PM
@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:
- Navigate to System Properties > System.
- Search for the glide.security.default_password property.
- Set the value of this property to the desired default password.
- 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:
- Use a transform map to map the fields from the Excel sheet to the user table.
- 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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 06:34 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 09:56 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2023 05:08 PM
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.
Thanks and regards
Vaine
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2023 06:15 PM
@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:
- Navigate to System Properties > System.
- Search for the glide.security.default_password property.
- Set the value of this property to the desired default password.
- 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:
- Use a transform map to map the fields from the Excel sheet to the user table.
- 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);