Setting up an outgoing webhook to an external url on table insert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2018 12:04 AM
I'm new to working/developing with ServiceNow. I'm currently using a Developer Kingston Instance. This is not for the faint-hearted. I have read numerous documents on the ServiceNow site and watched some videos on Youtube but I'm still not able to accomplish what I thought would be pretty straightforward. I've been able to do accomplish this task with other ticketing systems and a few web-based form tools by simply adding in my external webhook url which points to a php listener script. Voila, json data from one system is sent over to another instantly.
Anyhow, this is what I'm trying to accomplish and maybe someone can point me in the right direction. Maybe there is an easier way to do this. I'm open to any and all suggestions to make this integration possible.
I've created a new table called Onboarding and setup a form that I added into my Service Catalog. After a user inputs their values in the form and hits submit, I would like those values sent to my .php listener webhook automatically. I already have the php script setup to receive the json data and then it will add it to a mysql database. I need the values in that database because I have a Powershell script that will do some processing once a new record is added.
So far, I believe I need to configure an 'Outbound REST Message' using 'Post' and then setup a 'Business Rule' on the table to trigger 'On Insert'. I've setup a Request Bin and am currently using that as my endpoint so I can see what data (if any) is being sent. The only way I've been able to send any data over to the endpoint successfully was to create a variable called Testing and hardcoded a test value in the HTTP method. I added ${Testing} in the Content field and the Test Value was successfully sent when I did a test. I've tried using variables from the columns in my table like ${u_first_name} but no data gets sent. I've already setup Basic Authentication and setup my HTTP Header with Accept and Content-Type of application/json. I've even tried adding in X-UserToken since I saw that in the results on the API-Explorer page. Yes, I've tried throwing the entire kitchen sink but no luck so far.
If I can't get ServiceNow to send the data via an outbound REST message, I guess I will just have to use Powershell to connect directly to the ServiceNow instance using one of those API Explorer scripts. Poll the DB every x minutes to see if any new records have been added. If new record(s) added, pull the new data and then Put/Patch to update a status field on the record in ServiceNow so my script knows it was already pulled previously.
Sorry for the long winded post but I wanted to be thorough on what I needed and what I've tried so far. It's almost 3am my time. Maybe I need to call it a night.
Thanks in advance for any assistance, suggestions or help anyone can provide.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2018 12:23 AM
Scripted Outbound WS is what may help you @KT..
https://community.servicenow.com/community?id=community_blog&sys_id=886d2a29dbd0dbc01dcaf3231f9619b0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2018 12:23 AM
Hello,
First, if you only want this done for one order form, you don't need to add a Business Rule.
You should be able to find a Record Producer for your Service Catalog form. In the Record Producer is a script field where you can do most of all you want (although it is preferrable to use a REST connector out for handling authentication etc).
The script itself would use: "producer." to get various variables you have set (and their data).
If you want the variables from an end form in a business rule, they are current.variable.variable_name while the "normal" fields are current.field_name (such as Affected end user).
Add the data to a JSON and send it using (and this is the most basic you will ever find):
function newNpc(level){
try {
var r = new sn_ws.RESTMessageV2('HeroMuster_data', 'npc');
r.setStringParameterNoEscape('npc_level', level);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
return responseBody;
}
catch(ex) {
var message = ex.getMessage();
}
}
This function calls an outbound REST Message called HeroMuster_data
The outbound REST Message has a GET called "npc" that sends whatever is in the npc_level variable to:
https://openlegend.heromuster.com/api/npc/${npc_level}
Using authentication set in the REST Message.