Sure, Service-now.com is powerful when it comes to the web service, api, and other integration capabilities. Let’s say however, that you just want to create a method by which any HTTP enabled device could create a simple incident in your Service-now.com instance. You don’t want to have to authenticate…you just want to create an incident.
Security concerns – that is beyond this discussion other than to say you are allowing anyone to create a specific incident into your system.
Here is how you can go about enabling your service-now.com instance to allow these types of HTTP -> Incident requests. For this example we will use a “Password Reset” scenario.
Overview of Objective: I want to create an incident for a user that tells service-now.com that we need to reset that user’s password. This will be only through a simple HTTP request (eg. https://myinstance.service-now.com/URLIncident.do?USER=john.andersen).
First off, we are going to create a UI Page that is publicly accessible to the world. We are going to name that UI Page: “URLIncident”. At this point, leave your URLIncident UI Page at it’s default values. Save your UI Page, we’ll come back to it later.
Now we need to make that page a Public Page. In order to do this, you go to the Public Pages module in the “System Definition” application and add one for your URLIncident. (Please note: if your “Public Pages” module is not visible you may have to enable it: See “Activate the Public Pages Module” on the Serivce-now.com wiki.
Of course, a public client-side UI Page cannot talk to our server libraries. However, Service-now.com allows you to write Script Include files that are Client Callable through the GlideAjax library. In this example, we will name the Script Include: “URLIncident” just like our UI Page. Make sure your Script Include is set to be “Client Callable”.
Here is the following script for your Script Include:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | var URLIncident = Class.create(); URLIncident.prototype = Object.extendsObject(AbstractAjaxProcessor, { createIncident : function() { user_name = this.getParameter('sysparm_user_name'); gs.log("Creating Password Reset incident for " + user_name); inc = new GlideRecord("incident"); inc.caller_id = user_name; inc.short_description = "Reset Password for user " + user_name; inc.impact = 3; inc.urgency = 1; inc.insert(); }, _privateFunction : function() { // this function is not client callable } }); |
This code essentially takes an Ajax parameter (“user_name”) and creates and incident with “user_name” as the caller_id and as the target individual in the short description.
Now we will revisit our UI Page and add a client script to the page so that it will get run when the URL is accessed.
This will be your Client Script for the page:
1 2 3 4 5 6 7 8 9 10 11 | //This will get the username out of a ?USER=john.andersen GET parameter getParams = window.location.search; username = getParams.replace(/\?USER\=/, ""); //Set up the Ajax Call var ga = new GlideAjax('URLIncident'); ga.addParam('sysparm_name', 'createIncident'); ga.addParam('sysparm_user_name', username); //Call the server-side Ajax script include ga.getXMLWait(); |
Now, in order to test your setup, go to a browser that is not logged into your instance. If you had a user with a username of “john.andersen”, and your instance was “myinstance”, you would type the following URL into your browser:
https://myinstance.service-now.com/URLIncident.do?USER=john.andersen
You should be shown a blank page.
Now, in another browser that is logged into your Service-now.com instance, browse to your incident table and you should see a new Password Reset request for john.andersen.
Here is a quick video to demo this in action: