how to use snc pwdUtils in onafter transform script in csm

anp2023
Tera Contributor
 
2 REPLIES 2

KrishnaMohan
Giga Sage

@anp2023  Could you elaborate what is your use case or what you are trying to achieve.

Connectmustaq
Tera Contributor

To use snc_pwdUtils in an “onAfter” transform script for Customer Service Management (CSM) in ServiceNow, call methods from the global utility object snc_pwdUtils directly within your script to handle password operations (like enforcing password policies or generating hashes). For transform scripts, snc_pwdUtils is available in the global scope, but make sure the script runs server-side (transform scripts are server-side by default)
Example Usage in onAfter Transform Script
(function runTransformScript(source, map, log, target /*undefined onStart*/) {
// Example: Enforce password policy or hash a password field
var rawPwd = source.u_password; // Assuming u_password is a source staging field
if (rawPwd) {
var isCompliant = snc_pwdUtils.isPasswordCompliant(rawPwd);
if (!isCompliant) {
log.warn('Password does not meet policy: ' + rawPwd);
target.u_password_status = 'non-compliant';
} else {
var hashedPwd = snc_pwdUtils.encryptPassword(rawPwd);
target.u_password = hashedPwd;
target.u_password_status = 'compliant';
}
}
})(source, map, log, target);

Typical snc_pwdUtils Methods:-

  • isPasswordCompliant(password): Checks if the string meets current policy.
  • encryptPassword(password): Encrypts (hashes) the password for secure storage.
  • generateRandomPassword(length): Generates a random password of specified length.

Note: Only use these methods for import set transform scripts that manage password data securely and meet compliance goals.

Key Points:-
1) Transform scripts (onAfter, onBefore) run in ServiceNow’s server-side environment, giving access to global       utilities like snc_pwdUtils.

2)Always sanitize and avoid logging actual passwords.

    Test on non-production data first—transform map scripts can overwrite target record fields if misused.

3)This pattern lets ServiceNow transform maps enforce password policies or handle password encryption           automatically when importing or modifying user records in CSM workflows


if it is helpful, please hit the thumbs button and accept the correct solution by referring to this solution in the future it will be helpful to them.

 

Thanks & Regards,

Mohammed Mustaq Shaik