
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2016 08:57 PM
Hi ,
We have started to work on integrations and REST API's recently.
We are totally new and stuck , we could use some help.
There are couple fields in my record as below.
1) u_task
2) u_category
3) u_code
all the above are drop down.
We have a REST API which i added to rest message record and we are able to get the response.
We need to fetch that data and load the form with the values from it.
Can any one provide some help with the script what i can use?
Your help is much appreciated.
Thanks,
Raghu.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2016 02:20 AM
Assuming that you are using SNOW default forms and using client script, you are trying to add "options" to dropdowns, here is an example, which will add options to a control "u_category".
Note: I am assuming the response returned by your API/Web service is already in JSON format. If not, Please copy that response here. I put few alert statements for debugging. Remove them later, once you get it working.
ClientScript:
function onLoad() {
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('Test');
ga.addParam('sysparm_name','getCategories');
ga.getXML(getCategoriesOutput);
}
function getCategoriesOutput(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
var objJSON = JSON.parse(answer);
for(var loop = 0 ; loop < objJSON.categories.length;loop++)
{
alert(objJSON.categories[loop].Name);
g_form.addOption('u_category',objJSON.categories[loop].Value,objJSON.categories[loop].Name);
}
}
Server-side script include
var Test = Class.create();
Test.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCategories: function()
{
try {
/*var r = new sn_ws.RESTMessageV2('x_equi2_trouble_ti.Trouble Ticket Post', 'post');
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
return responseBody;*/
return '{\"categories\":[{\"Name":\"John\", \"Value\":\"Doe\"}, {\"Name":\"Anna\", \"Value\":\"Smith\"},{\"Name":\"Peter\", \"Value\":\"Jones\"}]}';
}
catch(ex) {
var message = ex.getMessage();
return "";
}
},
type: 'Test'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2016 09:09 PM
Hi Raghu,
We're going to need a little more information on this one.
Can you share some details about what you are using to pull the data? Is it a third party app pulling from ServiceNow?
What response did you get? It sounds like you got real data, but I don't understand what the problem is or what the desired outcome is.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2016 09:15 PM
Hi Chuck ,
Thanks for your attention here,
I am trying to create a custom app.
Getting data from other tool.
I added the end point in REST message and used get function to check the response.
Let me know what else you might need for help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2016 09:20 PM
Hi Raghu,
As per my understanding, you are using some other application, to call ServiceNow Table API. Are you getting successful response? If not, what is the error you are getting. Is it possible to put the specific code of calling SNOW table API here.
To call table API, along with passing authentication credentials, you also need to pass a header parameter "accept" with value "Application/JSON"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2016 09:24 PM
Hi Ram,
I am using servicenow to get data from other tool.
I am getting success full response, all i need to do is to call the REST function and populate the record on load.
We have a record called Problem Record. Once go into it and click new i need to get the data from rest service and add that to my above mentioned drop down.