- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2017 12:02 AM
Hi ,
i have a requirement in which i need to get the values from response and paste it in corresponding fields
here is the response
[{"index":3159,"Problem ID":"IM1202872","Resolution":"12\/14\/2016 17:25:15 (KISHORE BUSI): APPLY RULE 15, FILE REPLAYED PER EB.","Original Description":"The following File Gateway routing event occurred Route Event Details: ============================================================================== Event Code: FG_0455
in this response i am able to get and paste it in corresponding fields except Problem Id as it is having space between Problem and ID , could any one please help me in this
Here is the code
var gr = new GlideRecord('incident');
gr.addActiveQuery();
gr.addQuery('sys_id',sysid);
gr.query();
if(gr.next())
{
gr.description = responseBody;//--------> this is the Response which i get as shown above
var testJSON = JSON.parse(responseBody);gs.addInfoMessage("Response is directly saved in Description Field " + gr.number);
gs.addInfoMessage(responseBody);
gs.addInfoMessage("testJSON.index :"+testJSON[0].Resolution);/// i am getting this values
//gr.u_test = testJSON[0].index;
Object.keys(testJSON).forEach(function(key) {
var replaced = key.replace(' ', '');
if (key !== replaced) {
testJSON[replaced] = testJSON[key];
delete testJSON[key];
}
});
//console.log(testJSON);
gr.u_resolution = testJSON[0].Resolution;
gs.addInfoMessage(testJSON[0].ProblemID);
gr.update();
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2017 12:46 AM
Hi Sasidhar,
You are unable to get the values because of space. I checked at my side also so it was not retrieving.
Here is the updated code which retrieves all the values.
when trying to parse the space causes an issue. so i have declared a variable to hold that key and given it while parsing.
you can then pick individual variables and assign it in GlideRecord object.
Script:
var str = '[{"index":3159,"Problem ID":"IM1202872","Resolution":"12/14/2016 17:25:15 (KISHORE BUSI): APPLY RULE 15, FILE REPLAYED PER EB.","Original Description":"The following File Gateway routing event occurred Route Event Details: ============================================================================== Event Code: FG_0455"}]';
var parser = new JSONParser();
var parsedData = parser.parse(str);
var problemId = 'Problem ID';
var description = 'Original Description';
gs.print('Index is:'+parsedData[0].index);
gs.print('Problem ID is:'+parsedData[0][problemId]);
gs.print('Resolution is:'+parsedData[0].Resolution);
gs.print('Original Description is:'+parsedData[0][description]);
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2017 12:34 AM
There is space in Original Description as well, is that field works?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2017 12:40 AM
Hi Sasidhar,
Are you able to populate value from "Original Description" key as well since it also has space in between those 2 words.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2017 12:43 AM
Thanks for the Response ,
Sorry for not mentioning it no i can not get that Original description Also
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2017 12:46 AM
Hi Sasidhar,
You are unable to get the values because of space. I checked at my side also so it was not retrieving.
Here is the updated code which retrieves all the values.
when trying to parse the space causes an issue. so i have declared a variable to hold that key and given it while parsing.
you can then pick individual variables and assign it in GlideRecord object.
Script:
var str = '[{"index":3159,"Problem ID":"IM1202872","Resolution":"12/14/2016 17:25:15 (KISHORE BUSI): APPLY RULE 15, FILE REPLAYED PER EB.","Original Description":"The following File Gateway routing event occurred Route Event Details: ============================================================================== Event Code: FG_0455"}]';
var parser = new JSONParser();
var parsedData = parser.parse(str);
var problemId = 'Problem ID';
var description = 'Original Description';
gs.print('Index is:'+parsedData[0].index);
gs.print('Problem ID is:'+parsedData[0][problemId]);
gs.print('Resolution is:'+parsedData[0].Resolution);
gs.print('Original Description is:'+parsedData[0][description]);
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader