We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Encryption of Field Cause Script Include to Fail

Randy33
Tera Guru

I have a script include that imports employees from our HR System.  The issue is the script now fails when it executes the encryption code.  

 

//Encrypted fields
employee.u_last_four_ssn.setDisplayValue(this._getLastFour(d.ZY_CT_KEY_FLD));
employee.u_last_four_ssn.setContextID(encryptionID);
employee.u_dob.setDisplayValue(dob);
employee.u_dob.setContextID(encryptionID);
employee.u_phone.setDisplayValue(this._formatPhoneNumber(d.PHONE));
employee.u_phone.setContextID(encryptionID);
//employee.u_nid.setDisplayValue(d.ZY_CT_KEY_FLD);
employee.u_nid.setContextID(encryptionID);

//Update
employee.update();
 
else where in the code to get the encryption ID:
 
_getEncryptionID: function(encryptionName) {
var contextGR = new GlideRecord("sys_encryption_context");
contextGR.addQuery("name", encryptionName);
contextGR.query();
if (!contextGR.next()) {
gs.info("*********** No such encryption context " + encryptionName);
return "";
 
Any ideas as to why it is failing.  I'm not too familiar with encryption 😞
}
return contextGR.getUniqueValue();
},
1 REPLY 1

Ankur Bawiskar
Tera Patron

@Randy33 

if your script runs as system user then field level encryption is bypassed.

You can create a module access policy for your script include or business rule so that system ignores the encryption context for fields

Module access policy overview 

Step-by-Step Guide to Configuring an Encryption Module in ServiceNow 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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