The CreatorCon Call for Content is officially open! Get started here.

Import data in Encrypted field

Lucas Gl_nadel
Kilo Explorer

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,

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

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


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

jarodm
Mega Guru

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