ServiceNow Send REST call to iHub (Jira)

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,

  1. In the native ServiceNow window, navigate to System Definition > Business Rules > New.

  2. Click New and name it send Incident to iHub

  3. The Business Rule fields to be configured are as follows:

    Trigger

     

  4. '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

https://developer.servicenow.com/dev.do#!/learn/learning-plans/orlando/new_to_servicenow/app_store_learnv2_scripting_orlando_gliderecord

https://docs.servicenow.com/bundle/paris-application-development/page/app-store/dev_portal/API_reference/RESTMessageV2/reference/r_DirectRESTMessageV2Example.html

https://developer.servicenow.com/dev.do#!/learn/learning-plans/orlando/new_to_servicenow/app_store_learnv2_scripting_orlando_business_rule_scripts

https://developer.servicenow.com/dev.do#!/reference/api/orlando/server/sn_ws-namespace/c_RESTMessageV2API