GetDisplayValue not working correctly with encrypted field in robust transform Map
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2023 01:26 AM - edited ‎02-18-2025 09:19 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2023 01:44 AM
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:
-
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):
In your main transform script, use the scripted field transformation instead of(function transformEntry(source) { var encryptedValue = source.u_we.toString(); var grEncr = new GlideEncrypter(); var decryptedValue = grEncr.decrypt(encryptedValue); return decryptedValue; })(source); ​
getDisplayValue
. - 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2023 06:37 AM - edited ‎12-29-2023 06:38 AM
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