File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Server-Side Components/Business Rules/Use_case_Base64-Encode-Before-Save-And-Decode-on-Display Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 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 ) ;
13+
14+ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
15+ //Encode Before Saving Trigger: Before Insert/Update
16+
17+ ( function executeRule ( current , previous ) {
18+ if ( current . fieldName . changes ( ) ) {
19+ var plainText = current . fieldName + '' ;
20+ current . fieldName = GlideStringUtil . base64Encode ( plainText ) ;
21+ }
22+ } ) ( current , previous ) ;
23+
24+
25+ //If the field is new or updated, encodes its value to Base64. Saves the encoded string to the database.
26+
27+ // For Example User enters Hello World in fieldName.
28+ //Before saving : System encodes and stores SGVsbG8gV29ybGQ= in the database.
29+ //When the record is viewed : Display rule decodes it back to Hello World for the user.
You can’t perform that action at this time.
0 commit comments