GetDisplayValue not working correctly with encrypted field in robust transform Map

Lam_B
Tera Expert

Hello,

In my Robust Transform Map, I look into my table to check if a record already exists with the entries from my Excel file.

In this condition, I'm using "getDisplayValue" on an encrypted field, but I get an empty value. Interestingly, with the same record, when I apply "getDisplayValue" to another field, it works.

In my second condition, if the record doesn't exist, I create it from my script and retrieve the value associated to that encrypted field using the "getDisplayValue" function. Surprisingly, this time it works fine!

When I copied my code into a background script to see if I can get the display value of that encrypted field, it works again.

 

I'm a bit confused about why it is not working only from the robust transform map.

2 REPLIES 2

Ratnakar7
Mega Sage
Mega Sage

Hi @Lam_B ,

 

In ServiceNow, encrypted fields are handled differently when it comes to accessing their values in scripts. The getDisplayValue method does not work directly with encrypted fields due to security reasons. When you try to use getDisplayValue on an encrypted field within the context of a Transform Map script, it might not return the expected result.

Here are a couple of suggestions to handle encrypted fields in your Robust Transform Map:

  1. Use Scripted Field Transformations:

    • Create a new scripted field transformation for the encrypted field in your Transform Map.
    • In the script for this transformation, manually decrypt the field using appropriate methods and return the decrypted value.

    Example (assuming u_we is a standard ServiceNow encryption field):

    (function transformEntry(source) {
        var encryptedValue = source.u_we.toString();
        var grEncr = new GlideEncrypter(); 
        var decryptedValue = grEncr.decrypt(encryptedValue);
        return decryptedValue;
    })(source);
    ​
    In your main transform script, use the scripted field transformation instead of getDisplayValue.
  2.  Use Business Rules or Script Includes:
    • If the logic for working with encrypted fields is complex, consider encapsulating it in a Business Rule or Script Include.
    • From your Transform Map script, call the Business Rule or Script Include to perform the necessary operations on the encrypted field.

Thanks,

Ratnakar

 

Lam_B
Tera Expert

Hello @Ratnakar7 

 

When referring to an encrypted field, I mean that we encrypted it using Column Level Encryption. The field itself is a string. According to the documentation, to retrieve the value of the encrypted field, one should use 'getdisplayvalue.' This method works well for me when the record is newly created or accessed from a background script

 

From SN Doc : Updated getDisplayValue() and setDisplayValue() APIs that can return cleartext values and insert encrypted data for encrypted fields

 

link : https://docs.servicenow.com/bundle/vancouver-platform-security/page/administer/encryption/concept/c_...