Skip to content

Commit be113f0

Browse files
authored
Merge branch 'ServiceNowDevProgram:main' into main
2 parents 6f7f610 + a2cb846 commit be113f0

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
3+
//Encode Before Saving Trigger: Before Insert/Update
4+
5+
(function executeRule(current, previous) {
6+
if (current.fieldName.changes()) {
7+
var plainText = current.fieldName + '';
8+
current.fieldName = GlideStringUtil.base64Encode(plainText);
9+
}
10+
})(current, previous);
11+
//If the field is new or updated, encodes its value to Base64. Saves the encoded string to the database.
12+
13+
// For Example User enters Hello World in fieldName.
14+
//Before saving : System encodes and stores SGVsbG8gV29ybGQ= in the database.
15+
//When the record is viewed : Display rule decodes it back to Hello World for the user.
16+
17+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Decode on Display Trigger: Before Display
2+
////Decodes fieldName from Base64. Shows decoded value on the form.
3+
4+
(function executeRule(current) {
5+
if (current.fieldName) { // field name can be anything
6+
try {
7+
var decoded = GlideStringUtil.base64Decode(current.fieldName);
8+
current.setDisplayValue('fieldName', decoded);
9+
} catch (ex) {
10+
current.setDisplayValue('fieldName', '[Invalid Base64]');
11+
}
12+
}
13+
})(current);
14+
15+
//If the field is new or updated, encodes its value to Base64. Saves the encoded string to the database.
16+
17+
// For Example User enters Hello World in fieldName.
18+
//Before saving : System encodes and stores SGVsbG8gV29ybGQ= in the database.
19+
//When the record is viewed : Display rule decodes it back to Hello World for the user.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Base64 Encode/Decode Business Rule
2+
Overview
3+
4+
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.
5+
6+
It uses two Business Rules:
7+
8+
Before Insert/Update Rule : Encodes plain text into Base64 before saving to the database.
9+
10+
Display Rule : Decodes the Base64 value back into readable text when loading the record form.

0 commit comments

Comments
 (0)