ServiceNow Send REST call to iHub (Jira)
To send data when something happens in service now there are a few steps to go through. This can be done by using either the method below,
In the native ServiceNow window, navigate to System Definition > Business Rules > New.
Click New and name it send Incident to iHub
The Business Rule fields to be configured are as follows:
Trigger
'When to run' Tab Fields
Action
'Advanced' Tab Fields
Add the following script and change the URL and Auth to your parameters
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var requestBody;
var responseBody;
var status;
var sm;
try{
sm = new sn_ws.RESTMessageV2();
sm.setRequestHeader("Content-Type", "application/json");
sm.setHttpMethod("post");
sm.setEndpoint("https://_YOUR-JIRA-INSTANCE-URL_/rest/restfulintegrator/1.0/incoming");
sm.setBasicAuth("username","password");
var dataObject = {};
dataObject["id"] = current.sys_id.getDisplayValue();
dataObject["subject"] = current.short_description.getDisplayValue();
sm.setRequestBody(JSON.stringify(dataObject));
sm.setHttpTimeout(10000);
response = sm.execute();
responseBody = response.haveError() ? response.getErrorMessage() : response.getBody();
status = response.getStatusCode();
} catch(ex) {
responseBody = ex.getMessage();
status = '500';
} finally {
requestBody = sm ? sm.getRequestBody():null;
}
gs.info("Request Body: " + requestBody);
gs.info("Response: " + responseBody);
gs.info("HTTP Status: " + status);
})(current, previous);
References