- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2019 10:30 AM
i want to insert the rest api respopnse in service now table. in our company we are not allowed to create new tables, i need to insert the response in a table as json string.
please find the code.
var RL_LinkDetails = Class.create();
RL_LinkDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
callRLapi : function(){
var r = new sn_ws.RESTMessageV2('RL_rldbApi', 'Get_LinkDetails');
//override authentication profile
//authentication type ='basic'/ 'oauth2'
//r.setAuthentication(authentication type, profile name);
midserver = gs.getProperty('mid.server.rba_default');
r.setMIDServer(midserver);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var res= JSON.parse(responseBody);
//for(var i=0; i<res.length; i++) just want to try for 5 rows of data
for(var i=0; i<5; i++)
{
var ld = new GlideRecord('u_request_choices_lookup');
ld.u_label='rl';
ld.u_secondary_label='linkdetails';
ld.u_attributes=res[i].userKey;
ld.u_value= [
{"url":res[i].url},
{"shortDesc":res[i].shortDesc}
];
ld.insert();
}
},
type: 'RL_LinkDetails'
});
i am seeing the value column of the table showing data as org.mozilla.javascript.NativeArray.
please find the attached screen shot of the table.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2019 11:17 AM
var ex_value = [
{"url":res[i].url},
{"shortDesc":res[i].shortDesc}
];
ld.u_value=JSON.stringify(ex_value);
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2019 10:49 AM
try this
var ex_value = [
{"url":res[i].url},
{"shortDesc":res[i].shortDesc}
];
ld.u_value=ex_value.toString();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2019 10:49 AM
Basically you have convert the array to string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2019 11:14 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2019 11:17 AM
var ex_value = [
{"url":res[i].url},
{"shortDesc":res[i].shortDesc}
];
ld.u_value=JSON.stringify(ex_value);
Vinod Kumar Kachineni
Community Rising Star 2022