- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2018 02:54 AM
Hi Experts,
I am placing the below JSON object in incident Short Description field and called that through GlideRecord in background script, then tried to parse that using JSON.parse once i received but it throwing syntax error
JSON object : {"name":"George,ramesh","lastname":"Washington"}
If i hardcode in variable and use JSON.parse then it is working fine, if I place this in field and call that then no function from JSON class is working
When i tried with JSON.stringify() i am getting emty bracess {}
Code
var inc = new GlideRecord('incident');
inc.addEncodedQuery('sys_id=9714a35a0f4a2f4067c6590be1050e63');
inc.query();
if(inc.next()){
var str = inc.description;
var obj = = JSON.parse(str);
gs.info(‘The first name is ’ + obj.name);
}
Solved! Go to Solution.
- Labels:
-
Platform and Cloud Security
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2018 03:08 AM
Both these script will work, I have tested.
var inc = new GlideRecord('incident');
inc.addEncodedQuery('sys_id=9714a35a0f4a2f4067c6590be1050e63');
inc.query();
if(inc.next()){
var str = inc.description;
var obj = JSON.parse(str);
gs.info(‘The first name is ’ + obj.name);
}
//OR
var inc = new GlideRecord('incident');
inc.addEncodedQuery('sys_id=9714a35a0f4a2f4067c6590be1050e63');
inc.query();
if(inc.next()){
var str = inc.description;
var obj = new JSON().decode(str);
gs.info(‘The first name is ’ + obj.name);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2018 02:57 AM
Can you try this out once
var inc = new GlideRecord('incident');
inc.addEncodedQuery('sys_id=9714a35a0f4a2f4067c6590be1050e63');
inc.query();
if(inc.next()){
var str = inc.description.toString();
var obj = JSON.parse(str);
gs.info(‘The first name is ’ + obj.name);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2018 03:06 AM
There is a double equal sign on your JSON assignment.
var obj = = JSON.parse(str);
Correct it and it should work.
var obj = JSON.parse(str);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2018 03:08 AM
Both these script will work, I have tested.
var inc = new GlideRecord('incident');
inc.addEncodedQuery('sys_id=9714a35a0f4a2f4067c6590be1050e63');
inc.query();
if(inc.next()){
var str = inc.description;
var obj = JSON.parse(str);
gs.info(‘The first name is ’ + obj.name);
}
//OR
var inc = new GlideRecord('incident');
inc.addEncodedQuery('sys_id=9714a35a0f4a2f4067c6590be1050e63');
inc.query();
if(inc.next()){
var str = inc.description;
var obj = new JSON().decode(str);
gs.info(‘The first name is ’ + obj.name);
}