Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

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 folowing 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://testing.rixter.se/rest/restfulintegrator/1.0/incoming?token=be388056-9f23-4eaf-9247-ae6219933d67");
		sm.setBasicAuth("theIntegrationUser","ABC1243");
		
		gs.info("current: ",  current.table);
		gs.info("pre:" , previous);
		
		sm.setRequestBody(JSON.stringify(current));
		
		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://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

  • No labels