Skip to content

Commit 349dc9e

Browse files
authored
Format JSON Data in String Fields (#2172)
* Create test.js * Delete Specialized Areas/Fix scripts/test.js * Create script.js * Create README.md * Create script.js * Create README.md * Delete Specialized Areas/Beautify JSON Data in String Fields directory * Update README.md
1 parent 45fd932 commit 349dc9e

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
**Details**
2+
1. This script will format the JSON data in string fields on forms.
3+
2. There is on OOB attribute "json_view" which can be added to field but it always reqires an extra click and has loading time issues.
4+
5+
**How to use**
6+
1. Run this script as Fix Script.
7+
2. Replace the table name and encoded query as per your requirement.
8+
3. Replace the field to be formatted as per the table selected.
9+
10+
**Before Formatting**
11+
<img width="956" height="371" alt="Before1" src="https://github.com/user-attachments/assets/1b35dfaf-d2ad-44c3-bbd2-d3198664073b" />
12+
13+
**After Formatting**
14+
<img width="950" height="382" alt="After" src="https://github.com/user-attachments/assets/c3a1c3c0-48bd-4d2f-9e27-fea0ed86004d" />
15+
16+
JSON.stringify() documentation : https://www.geeksforgeeks.org/javascript/javascript-json-stringify-method/
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
This script will format the JSON data in string fields on forms.
3+
There is on OOB attribute "json_view" which can be added to field but it always reqires an extra click and has loading time issues.
4+
*/
5+
var chReq = new GlideRecord('change_request'); // Glide table.
6+
chReqch.get('c83c5e5347c12200e0ef563dbb9a7190'); // sys_id of record, can be replaced with encoded query for multiple records.
7+
8+
chReq.u_json_field = JSON.stringify(JSON.parse(chReq.u_json_field), null, "\t");
9+
chReq.update();

0 commit comments

Comments
 (0)