Setting Encryption in Workflow

Kyle Wiley
Mega Expert

I am trying to push data from variables in a Catalog Item into an encrypted field on the sc_req_item table without any luck.   Here is the script I am currently using:

current.approval = 'approved';

// Sets the field encryption contextID

current.u_encrypted_info.setContextID("82a9095d4f8fd600b04176601310c70a"); // sys_encryption_context.sys_id

// Sets the field information

current.u_encrypted_info += "MRN Name: " + current.variable_pool.mrn_name;

current.u_encrypted_info += "\nDOB: " + current.variable_pool.dob;

current.u_encrypted_info += "\nMRN: " + current.variable_pool.mrn;

The encrypted field on the form is not showing at all once the workflow processes, I am assuming because there is an error in the code.   I am using the sys_id from the sys_encryption_context table.  

Am I missing something?   Do I need to run a query on the sys_encryption_context table first and use the GlideRecord return?

1 ACCEPTED SOLUTION

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

I believe you need to use the setDisplayValue() function to set the value of your u_encrypted_info field because setting the actual value will store it unencrypted.



var encryptedInfo = "MRN Name: " + current.variable_pool.mrn_name;


encryptedInfo += "\nDOB: " + current.variable_pool.dob;


encryptedInfo += "\nMRN: " + current.variable_pool.mrn;



current.u_encrypted_info.setDisplayValue(encryptedInfo);


current.u_encrypted_info.setContextID("82a9095d4f8fd600b04176601310c70a"); // sys_encryption_context.sys_id



See this example: Encryption Scripting - ServiceNow Wiki


View solution in original post

3 REPLIES 3

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

I believe you need to use the setDisplayValue() function to set the value of your u_encrypted_info field because setting the actual value will store it unencrypted.



var encryptedInfo = "MRN Name: " + current.variable_pool.mrn_name;


encryptedInfo += "\nDOB: " + current.variable_pool.dob;


encryptedInfo += "\nMRN: " + current.variable_pool.mrn;



current.u_encrypted_info.setDisplayValue(encryptedInfo);


current.u_encrypted_info.setContextID("82a9095d4f8fd600b04176601310c70a"); // sys_encryption_context.sys_id



See this example: Encryption Scripting - ServiceNow Wiki


That worked!   Thanks!!!


Aditya Telideva
ServiceNow Employee
ServiceNow Employee

Hi Kyle,


i would also recommend you to go through: Existing field Encryption


Existing field Encryption


Thanks,


Aditya Telidevara