- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 07:01 AM
Hi,
JSON.stringfy() was working if I directly pass JSON object to a variable. If I try it with glide record that's not working.
For your ref PFA:
Scenario 1:
Passing JSON object directly to a variable:
var str = {"u_supply_planner_field_1":[{"original_value":"abc","changed_value":"ABC"}]};
var res = JSON.stringify(str);
gs.print(res);
var parsedData = JSON.parse(res);
gs.print(parsedData.u_supply_planner_field_1[0].original_value);
Output:
Scenario 2:
Gliding Record:
var caseR = new GlideRecord('sn_customerservice_case');
caseR.addEncodedQuery('state=10^number=CS0001031');
caseR.query();
if(caseR.next()){
gs.print(caseR.short_description);
var jsonObj = caseR.u_json_output;
gs.print(jsonObj);
var res = JSON.stringify(jsonObj);
gs.print(res);
var parsedData = JSON.parse(jsonObj);
gs.print(parsedData);
gs.print(parsedData.u_supply_planner_field_1[0].original_value);
}
Output:
Thanks in advance 🙂
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 07:11 AM - edited 02-20-2024 07:13 AM
Hi @Aruna Sree Yela ,
Use this...
var jsonObj = {}; // declare empty object here...
var res = {} ; // declare your res here
var parsedData = {} // declare your objects here...
var caseR = new GlideRecord('sn_customerservice_case');
caseR.addEncodedQuery('state=10^number=CS0001031');
caseR.query();
if(caseR.next()){
gs.print(caseR.short_description);
jsonObj = caseR.u_json_output;
gs.print(jsonObj);
res = JSON.stringify(jsonObj);
gs.print(res);
parsedData = JSON.parse(jsonObj);
gs.print(parsedData);
gs.print(parsedData.u_supply_planner_field_1[0].original_value);
}
So whats happening here is the
var jsonObj = caseR.u_json_output;
it is declaring the jsonObj again so try to declare it outside the if // Refer the above code...
If my solution helps you do hit the like button and accept the solution.
Thanks and Regards,
Saurabh Dubey.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 07:14 AM
From the response I understand the data is store in table as stringified version. Also observerved that your string has additional semicolum at the end. So, your code should be below:
var caseR = new GlideRecord('sn_customerservice_case');
caseR.addEncodedQuery('state=10^number=CS0001031');
caseR.query();
if(caseR.next()){
gs.print(caseR.short_description);
var jsonStr = caseR.u_json_output.toString();
gs.print(jsonStr);
//var res = JSON.stringify(jsonObj);
//gs.print(res);
if(jsonStr.substring(jsonStr.length-1) == ";"){ // Check if the string has semicolon at the end
jsonStr = jsonStr.slice(0, -1); // remove the last charactor
}
var parsedData = JSON.parse(jsonStr);
gs.print(parsedData);
gs.print(parsedData.u_supply_planner_field_1[0].original_value);
}
Palani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 07:11 AM - edited 02-20-2024 07:13 AM
Hi @Aruna Sree Yela ,
Use this...
var jsonObj = {}; // declare empty object here...
var res = {} ; // declare your res here
var parsedData = {} // declare your objects here...
var caseR = new GlideRecord('sn_customerservice_case');
caseR.addEncodedQuery('state=10^number=CS0001031');
caseR.query();
if(caseR.next()){
gs.print(caseR.short_description);
jsonObj = caseR.u_json_output;
gs.print(jsonObj);
res = JSON.stringify(jsonObj);
gs.print(res);
parsedData = JSON.parse(jsonObj);
gs.print(parsedData);
gs.print(parsedData.u_supply_planner_field_1[0].original_value);
}
So whats happening here is the
var jsonObj = caseR.u_json_output;
it is declaring the jsonObj again so try to declare it outside the if // Refer the above code...
If my solution helps you do hit the like button and accept the solution.
Thanks and Regards,
Saurabh Dubey.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 07:14 AM
From the response I understand the data is store in table as stringified version. Also observerved that your string has additional semicolum at the end. So, your code should be below:
var caseR = new GlideRecord('sn_customerservice_case');
caseR.addEncodedQuery('state=10^number=CS0001031');
caseR.query();
if(caseR.next()){
gs.print(caseR.short_description);
var jsonStr = caseR.u_json_output.toString();
gs.print(jsonStr);
//var res = JSON.stringify(jsonObj);
//gs.print(res);
if(jsonStr.substring(jsonStr.length-1) == ";"){ // Check if the string has semicolon at the end
jsonStr = jsonStr.slice(0, -1); // remove the last charactor
}
var parsedData = JSON.parse(jsonStr);
gs.print(parsedData);
gs.print(parsedData.u_supply_planner_field_1[0].original_value);
}
Palani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 07:26 AM
Hi,
As per my understanding, the data getting returned in string format. Can you please check type of jsonObj. Please convert it Object and then try to stringify and parse.
Please mark it as helpful. If my answer is correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 07:41 AM
Hi @Aruna Sree Yela , This is the second thread I have seen from you regarding the Objects question one was for the workflow and another is this,
Do refer this video.
If you speak hindi : https://www.youtube.com/watch?v=ju5j7rfXXTE
If you speak English : https://www.youtube.com/watch?v=wI1CWzNtE-M
Please mark my solution helpful if it helps you
Thanks,
Saurabh