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:




    Name

    The name of the business rule.


    Table

    The table that this business rule will run on.

    ‘Incident’ [incident] or any other table

    Active

    Set to true to enable this business rule.

    true
    Advanced

    Set to true to reveal the advanced version o the form.

    true

    Trigger


  4. 'When to run' Tab Fields




    When

    When this business rule should execute relative to the database operation.

    async
    Insert

    Select this check box to execute the business rule when a record is inserted into the database.

    true
    Update

    Select this check box to execute the business rule when a record is updated.

    true
    Order

    The sequence in which this business rule should run.


    1,000,000,000

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