Servicenow – encrypt a field using encryption context

I wanted to encrypt a field by using encryption context and de-encrypt it. Below are the setups and scripts to test it. I am using ‘admin’ rights.

UI Macro:

ui macro

Plugin:

plugin

At Table structure:

field

At the form, I can view field (cipher) as string, showing encryption context table sys_id. This can update and sys_id over there.

Below will be the script:


   var contextGR = new GlideRecord("sys_encryption_context");
   contextGR.initialize();
   contextGR.get("encrypt_sys_id");
   gs.addInfoMessage("encrypt context id:"+contextGR.sys_id+'');

   var person= new GlideRecord("x_person");
   person.addQuery('ciphers', contextGR.sys_id+'');
   person.query();
   while (person.next()) {
	break;
   }

   gs.addInfoMessage("person sys id:"+person.sys_id+'');

   person.setDisplayValue('ciphers','abcde');
   person.setContextID(contextGR.sys_id+'');
   gs.addInfoMessage('decrypted val: '+person.ciphers.getDisplayValue());

 

Result:

result

Hope this can help!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s