Calling an external service (Simple HTTP GET) from Service Now Client or Server.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2013 08:34 AM
Hello,
I want to write a Client Side Script (onSubmit on the Incident form). After evaluating an incident submit I want to make a HTTP request to an external server, nothing fancy but a simple GET will serve the need.
Now I am uncertain if this is possible to begin with. Does client side scripts provide HTTP functionality or must I call a server side script from the client script and in turn make the HTTP request from the server?
The most straightforward solution for us would be to do it from the client but the only Service Now Related resource I found that seemed relative had it done on the server by using the java/apache http library:
http://servicenowdiary.com/2011/11/custom-http-get-request-to-a-server/
Any input will be appreciated!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2013 02:08 AM
Here you go - In this example I'm just pulling in all the Incidents from my own Service Now instance [ You can replace the URL with anything which can GET you something] - This is written as a onLoad client script, you can as well write it onSubmit.
The trick here is to use prototype.js's Ajax Method here : http://prototypejs.org/learn/introduction-to-ajax
As this is a very basic example('coz I don't know what you are trying to do) I just reused the example in the above page.
Type: OnLoad
URL - the URL that you want, here for simplicity I'm using Service Now's JSON processor to fetch all incidents. Any URL which can get will do, Including twitter 🙂
function onLoad() {
var url = "https://"+<my_instance>+".service-now.com/incident.do?JSON';
new Ajax.Request(url, {
method:'get',
onSuccess: function(transport) {
alert(transport.status);
var response = transport.responseText || "no response text";
alert("Success! \n\n" + response);
},
onFailure: function() { alert('Something went wrong...'); }
});
}
Edit : The above code will alert all the incidents in your system, in JSON format.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2013 03:09 AM
Thank you for the reply Abhiram,
much appreciated.
I will try it out and get back if there are any issues I'm still wondering about!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2013 10:48 AM
Did this work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2013 06:06 AM
Hello,
Due to focus on another project this has been put on ice for a short while. I will notify as soon as I have tried it.
However, I am have some doubts on whether it will work since we will aim an URL outside of the current domain the client is requesting information from (i.e causing cross-site scripting). If this proves to be the case I will have to migrate the script to the server side I assume.
But, I will let you know as soon as I have tried it out.
Best Regards