- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2020 12:47 AM
Hi All,
How to pull below Json data from a field. I am storing the Json data on form in a particular field that is string field.
The below data is from a catalog item details.
{
'sysparm_id': '0d08837237153000158bbfc8bcbe5d02',
'sysparm_quantity': '1',
'variables':{
'example_var1': 'at_and_t_mobility',
'example_var2': '500MB',
'example_var3': 'eighteen_months',
'example_var4': 'slate',
'example_var5': 'sixtyfour'
}};
I want to get the variables and sysparm_id. How to get from a variables.
Thank You,
Sai.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2020 12:54 AM
try now.
var json = {
'sysparm_id': '0d08837237153000158bbfc8bcbe5d02',
'sysparm_quantity': '1',
'variables':{
'example_var1': 'at_and_t_mobility',
'example_var2': '500MB',
'example_var3': 'eighteen_months',
'example_var4': 'slate',
'example_var5': 'sixtyfour'
}};
var ab = JSON.stringify(json);
var op = JSON.parse(ab);
gs.print(op.sysparm_id);
gs.print(op.variables.example_var1); // this way you will get variables object details.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2020 12:54 AM
try now.
var json = {
'sysparm_id': '0d08837237153000158bbfc8bcbe5d02',
'sysparm_quantity': '1',
'variables':{
'example_var1': 'at_and_t_mobility',
'example_var2': '500MB',
'example_var3': 'eighteen_months',
'example_var4': 'slate',
'example_var5': 'sixtyfour'
}};
var ab = JSON.stringify(json);
var op = JSON.parse(ab);
gs.print(op.sysparm_id);
gs.print(op.variables.example_var1); // this way you will get variables object details.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2020 01:02 AM
Hi Harsha,
I have tested this through background script its working.
When I run the same code through business rule its not working.
var json = { // This Json name is not there in my data.
'sysparm_id': '0d08837237153000158bbfc8bcbe5d02',
'sysparm_quantity': '1',
'variables':{
'example_var1': 'at_and_t_mobility',
'example_var2': '500MB',
'example_var3': 'eighteen_months',
'example_var4': 'slate',
'example_var5': 'sixtyfour'
}};
The json data like below.
{
'sysparm_id': '0d08837237153000158bbfc8bcbe5d02', (this is the sys_id)
'sysparm_quantity': '1',
'variables':{
'example_var1': 'at_and_t_mobility',
'example_var2': '500MB',
'example_var3': 'eighteen_months',
'example_var4': 'slate',
'example_var5': 'sixtyfour'
}};
var ab = JSON.stringify(current.description);
var op = JSON.parse(ab);
gs.addInfoMessage(op.sysparm_id);
gs.info(op.sysparm_id);
gs.info(op.variables.example_var1);
Thank You,
Sai.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2020 01:03 AM
share your business rule code, you have to directly use the JSON.parse()

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2020 01:05 AM
eg:
var ab = current.getValue('JSON Field name');
var op = JSON.parse(ab);
gs.log('JSON value is '+ op); // it should come object object
gs.addInfoMessage(op.sysparm_id);
gs.info(op.sysparm_id);
gs.info(op.variables.example_var1);