send data from ServiceNow to other applications using REST
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2016 08:48 PM
Hi, I have to send couple of fields info to an application via REST. I went through wiki but couldnt understand much. Can someone please let me know how to do it.
I understand that I have to go to REST Message and update the end point. Lets say I have 3 fields A, B, C, which I need to send the info of these fields to an external application. Now when I get inside POST, what should I do now? Thanks.
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2016 10:50 AM
Hi Tony, I have created a BR as below, passing 2 fields(u_endpoint and u_sites) in the table from where I wanted to send the data. The values that I pass are used in 'Content' in the HTTP Method - post, as in the pic. Am I right in doing that?
FYI ... The external application expects values as inendpt and insites and thats why I have used inendpt=${endpt}&insites=${sites}. Am I right here?
var r = new RESTMessage('VR', 'post');
r.setStringParameter('u_endpoint', endpt);
r.setStringParameter('u_sites', sites);
var response = r.execute();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2016 05:26 AM
Hi BD,
I am not sure about the specifics.
But I do have some generic advice which you may find helpful.
1) I did mention earlier
" .. make sure the documentation you are looking at is aligned withe the version of your instance."
What is the version of your instance?
Is it Eureka?
Then your use of RESTMessage rather than RESTMessageV2 is fine RESTMessageV2 is available from Fuji onwards.
Is it Fuji or later?
Then you should use RESTMessageV2.
2) You mention this is the code:
var r = new RESTMessage('VR', 'post');
r.setStringParameter('u_endpoint', endpt);
r.setStringParameter('u_sites', sites);
var response = r.execute();
}
However I would suggest using the the GUI to as a framework for creation and testing.
Then generating the code for the business rule preview script usage.
The links here are for Geneva
..
Navigate to System Web Services > REST Message.
Click New.
etc
..
Auto-generate variables - which you can use to generate the r.setStringParameter(.... );
..
Generate a REST message script preview
3) Also it is a good idea to try/catch errors and to get some more info from the response - along the lines of:
try {
var r = new sn_ws.RESTMessageV2('The name of the REST message record', 'post');
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.getMessage();
}
Also a good idea to check you are sending what you think you are sending:
gs.info("endpt = " + endpt);
gs.info("endpt = " + sites);
var r = new RESTMessage('VR', 'post');
r.setStringParameter('u_endpoint', endpt);
r.setStringParameter('u_sites', sites);
var response = r.execute();
}
Any questions arising?
Best Regards
Tony
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2017 08:45 AM
Hi Anthony,
I am using Eureka and below is my line of codes, which are executing but inserting the blank rows only.
createtticket: function(curr) {
try {
var r = new RESTMessage('Dev', 'post');
r.setStringParameter('u_number', curr.number);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
if (httpStatus == "200") {
json.update();
}
}
catch(ex) {
throw "Internal Scripting Error reported:" + ex.getMessage();
}
},
Any idea what needs to be modified?