Import data in Encrypted field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-09-2017 01:48 AM
Hi,
I'm trying to import data in the sys_user table. In this table, I have an Encrypted field : Badge Number.
Of course, the field do not encrypt when I import data into it.
So I try to use a script to set the Encryption Context in an Transform Script onAfter :
var contextGR = new GlideRecord("sys_encryption_context");
contextGR.addQuery("name", "EncryptionContextTEST");
contextGR.query();
if (!contextGR.next())
{
gs.log("*********** No such encryption context " + encryptionContextName);
return;
}
var encryptionID = contextGR.getUniqueValue();
if (encryptionID == "") return;
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', target.sys_id);
gr.query();
if (gr.next())
{
gr.u_badge_number.setContextID(encryptionID);
gr.u_badge_number.setDisplayValue(source.u_badge_number.toString());
gr.update();
}
But unfortunately this doesn't work
I have tried to do this in a Field Map - Script, with the getElements function, ...
Is there a way to do this ?
Thanks,
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2017 07:07 AM
Hi Lucas,
As far as I know Import Sets cannot add data to encrypted fields.
You can explore more on community.
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2017 08:34 AM
Your sample code looks good, and would likely work by a logged in user in a BR or UI Action....
But...
Encryption context can't be used in the background(via system or impersonation). It can only be used in the foreground by the actual user with the role/context. Since transform maps are executed by system, due to the strict role-base-access-control (RBAC), it won't be able to access the data stored in those fields.
Reference: Async business rules