Skip to content

Commit dfa7bcf

Browse files
Before_BR_script.js
1 parent 7c24ccc commit dfa7bcf

File tree

1 file changed

+3
-15
lines changed
  • Server-Side Components/Business Rules/Use_case_Base64-Encode-Before-Save-And-Decode-on-Display

1 file changed

+3
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
1-
// Decode on Display Trigger: Before Display
2-
////Decodes fieldName from Base64. Shows decoded value on the form.
3-
(function executeRule(current) {
4-
if (current.fieldName) { // field name can be anything
5-
try {
6-
var decoded = GlideStringUtil.base64Decode(current.fieldName);
7-
current.setDisplayValue('fieldName', decoded);
8-
} catch (ex) {
9-
current.setDisplayValue('fieldName', '[Invalid Base64]');
10-
}
11-
}
12-
})(current);
131

14-
-----------------------------------------------------------------------------------
2+
153
//Encode Before Saving Trigger: Before Insert/Update
164

175
(function executeRule(current, previous) {
@@ -20,10 +8,10 @@
208
current.fieldName = GlideStringUtil.base64Encode(plainText);
219
}
2210
})(current, previous);
23-
24-
2511
//If the field is new or updated, encodes its value to Base64. Saves the encoded string to the database.
2612

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

0 commit comments

Comments
 (0)