Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@


//Encode Before Saving Trigger: Before Insert/Update

(function executeRule(current, previous) {
if (current.fieldName.changes()) {
var plainText = current.fieldName + '';
current.fieldName = GlideStringUtil.base64Encode(plainText);
}
})(current, previous);
//If the field is new or updated, encodes its value to Base64. Saves the encoded string to the database.

// For Example User enters Hello World in fieldName.
//Before saving : System encodes and stores SGVsbG8gV29ybGQ= in the database.
//When the record is viewed : Display rule decodes it back to Hello World for the user.


Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Decode on Display Trigger: Before Display
////Decodes fieldName from Base64. Shows decoded value on the form.

(function executeRule(current) {
if (current.fieldName) { // field name can be anything
try {
var decoded = GlideStringUtil.base64Decode(current.fieldName);
current.setDisplayValue('fieldName', decoded);
} catch (ex) {
current.setDisplayValue('fieldName', '[Invalid Base64]');
}
}
})(current);

//If the field is new or updated, encodes its value to Base64. Saves the encoded string to the database.

// For Example User enters Hello World in fieldName.
//Before saving : System encodes and stores SGVsbG8gV29ybGQ= in the database.
//When the record is viewed : Display rule decodes it back to Hello World for the user.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Base64 Encode/Decode Business Rule
Overview

This setup demonstrates how to store field data securely in Base64 format in the database, while still displaying it as human-readable text to end users in ServiceNow.

It uses two Business Rules:

Before Insert/Update Rule : Encodes plain text into Base64 before saving to the database.

Display Rule : Decodes the Base64 value back into readable text when loading the record form.
Loading