- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2015 06:39 AM
Hello all. I need to retrieve an XML file via a non ServiceNow URL that will be different every single time it's used. I then need to parse that XML file to populate fields on a new Incident ticket.
I'm pretty sure I can manage the parsing bit, but I haven't figured out how I can retrieve the file.
If I go to the URL directly in a browser, I get a "file download" prompt as opposed to the XML being presented in the browser. I'm not sure if that complicates matters or not.
I've tried using XMLHttpRequest, but that doesn't seem to exist on the server side:
org.mozilla.javascript.EcmaError: "XMLHttpRequest" is not defined.
I found a reference to GlideHttpRequest, but I couldn't find much detail on it at all, and the little I could find implies it's only used for internal ServiceNow stuff.
I suspect I can use jQuery to do this, but so far I'm at a loss how to do this.
Any suggestions?
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2015 12:03 PM
I found this:
Custom HTTP GET Request to a server
I adapted the code to this:
var httpclient = Packages.org.apache.commons.httpclient;
var HttpClient = httpclient.HttpClient;
var GetMethod = httpclient.methods.GetMethod;
var client = new HttpClient();
var get = new GetMethod('<URL>');
var status = client.executeMethod(get);
var result = get.getResponseBodyAsString();
gs.log(result);
And I'm getting the XML. Now to parse it...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2015 12:03 PM
I found this:
Custom HTTP GET Request to a server
I adapted the code to this:
var httpclient = Packages.org.apache.commons.httpclient;
var HttpClient = httpclient.HttpClient;
var GetMethod = httpclient.methods.GetMethod;
var client = new HttpClient();
var get = new GetMethod('<URL>');
var status = client.executeMethod(get);
var result = get.getResponseBodyAsString();
gs.log(result);
And I'm getting the XML. Now to parse it...