How to insert the data into the table using "REST Message" get Method()?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2015 05:11 AM
Hi,
I have the API which return "JSON" object, configured the API with Rest Message. It's responding properly, But i need to insert the "Json" object response into one table.
Can anyone suggest how to do it?
Regards,
Jennifer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2015 05:24 AM
Hi Jennifer,
see below example.
it is calling other instance for incident data. which is JSON. i am then using that data to create records in my instance. modify according to your need.
var restMessage = new sn_ws.RESTMessageV2(); |
restMessage.setBasicAuth("username", "passwr");
restMessage.setHttpMethod("get");
restMessage.setEndpoint("http://zuzuinstance.service-now.com/api/now/table/incident");
restMessage.setRequestHeader("Accept","application/json");
restMessage.setQueryParameter('sysparm_limit','2');
restMessage.setQueryParameter('sysparm_fields','number,short_description'); |
var response = restMessage.execute();
gs.addInfoMessage("executed"); |
var res = response.getBody();
var js = JSON.parse(res); | ||
var result = js.result; | ||
for (var i = 0;i < result.length ; i++){ | ||
var number = result[i].number; | ||
var short_desc = result[i].short_description; | ||
var gr = new GlideRecord('incident'); | ||
gr.initialize(); | ||
gr.number = number; | ||
gs.addInfoMessage(number); | ||
gr.short_description = short_desc; | ||
gr.insert(); | ||
} Let me know if you have questions. |
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2015 07:54 PM
Hi
I tried the above code but it's not working. There is no error also no response.
can you suggest other way to do?
Regards
Jennifer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2015 10:33 PM
Hi Jennifer,
Have you validated that your API end point is retrieving the information that you're expecting? You could validate your API and the credentials/headers used by using products like postman or runscope.
I hope this helps!
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2015 11:15 PM
Hi Jennifer,
1) where are you executing that code from? make sure that code is getting executed.
2)make sure endpoint and credential are correct(if any). try to query from POSTMAN.
3)can you do console.log(js) after this line var js = JSON.parse(res); see the result in browser's console. tell me what data is coming.