Skip to content

Commit e452046

Browse files
Script.js
1 parent 8451bfd commit e452046

File tree

1 file changed

+25
-0
lines changed
  • Server-Side Components/Business Rules/Base64-Encode-Before-Save-And-Display

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//This is Before Insert/Update Business Rule to automatically store sensitive data in Base64 form.
2+
3+
(function executeRule(current, previous) {
4+
if (current.u_field1.changes()) {
5+
var plainText = current.u_field1 + '';
6+
current.u_field1 = GlideStringUtil.base64Encode(plainText);
7+
}
8+
})(current, previous);
9+
10+
11+
12+
13+
14+
//this is Display busiess rule to make sure users see the decoded text instead of Base64
15+
16+
(function executeRule(current) {
17+
if (current.u_field1) {
18+
try {
19+
var decoded = GlideStringUtil.base64Decode(current.u_field1);
20+
current.setDisplayValue('u_field1', decoded);
21+
} catch (ex) {
22+
current.setDisplayValue('u_field1', '[Invalid Base64]');
23+
}
24+
}
25+
})(current);

0 commit comments

Comments
 (0)