Skip to content

Commit 2dacbe4

Browse files
authored
Add getJson function for JSON table retrieval
Implement getJson function to retrieve table fields as JSON.
1 parent 883c547 commit 2dacbe4

File tree

1 file changed

+12
-0
lines changed
  • Specialized Areas/Fix scripts/Create Table JSON

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
getJson('incident', 'rfc,caller_id'); // pass table name and field names comma separated.
2+
function getJson(tableName, fields) {
3+
var jsonObj = {};
4+
var eQry = gs.nil(fields) ? 'name=' + tableName : 'name=' + tableName + '^elementIN' + fields; // generate JSON of enitre table if no fields are specified.
5+
var dict = new GlideRecord('sys_dictionary');
6+
dict.addEncodedQuery(eQry);
7+
dict.query();
8+
while (dict.next()) {
9+
jsonObj[dict.element] = '';
10+
}
11+
gs.print(JSON.stringify(jsonObj));
12+
}

0 commit comments

Comments
 (0)