Skip to Content
Technical Articles

Read ServiceNow incidents with REST API in SAP IRPA

Introduction

This blog post concentrates on the use of REST API in SAP IRPA to read incident details from ServiceNow Developer Instance. If you are looking for the OpenConnectors method to connect with SNOW tool, please follow this link.

Target Audience:

The audience for this blog post will need a basic understanding of SAP IRPA platform and knowhow in Javascript. To learn all about setting up IRPA studio please follow this blog post and you will find the content in this article more meaningful.

Use Case:

ServiceNow interaction with SAP IRPA opens new possibilities for automation. It can be used to scan new incidents and act upon with SAP IRPA based on the incident type and description. The below process only explains how we can get hold of the data present in the ServiceNow database and make it available in SAP IRPA. This process can be further extended by practitioners to act upon it and fully automate action on the opened incident.

Implementation:

We will be doing it in 2 steps.

  1. Create Service now developer instance and acquire developer credentials.
  2. Build SAP IRPA bot to read data from ServiceNow Rest API for Table.

Step 1: Create Service now developer instance.

Navigate to this link.

If you do not have it yet, Create and activate the account. and note down the credentials used to log into the Admin panel.

Once the account is activated, search for ‘REST’ on the search panel on the left. and select REST API Explorer.

You will see multiple tables present in the dropdown list. We will be looking into the incidents part so search and note down the relevant table name.

 

 

 

By selecting the table and pressing the SEND button you will see the complete URL that we will use in our example.

Step 2: Read data from ServiceNow Rest API for Table

Create a new project in SAP IRPA Automation Desktop Studio.

Create a new workflow like below.

The web service call step will hold below parameters.

We need to modify the generated code to suit our needs.

GLOBAL.step({ Call_a_web_service: function(ev, sc, st) {
	var $data$;
	var x;
	var i;
	var rootData = sc.data;

	ctx.workflow('newWorkflow', '439a303d-be99-4717-bde7-8b1f006cd49a') ;
	ctx.log("Call a web service");
	// Call a web service
	ctx.ajax.call({
	  url: 'https://dev1234.service-now.com/api/now/table/incident?sysparm_limit=10',
		method: e.ajax.method.get,
	    username: 'username',
		password: 'password',
		data: rootData.API.Input,
	  contentType: e.ajax.content.json,
	  success: function(res, status, xhr) {
			for( i = 0 ; i < 10 ; i++ ){
					x = res.result[i];
					ctx.log('Category : '+ x.category );
					ctx.log('Incident No : ' + x.number);
  				    ctx.log('Severity : ' + x.severity);
					ctx.log('Description : ' + x.description);
					ctx.log('-----------------------------------------');
				};	
		return;
	  },
	  error: function(xhr, error, statusText) {
	    ctx.log(' ctx.ajax.call  error: ' + statusText);
	  }
	});
}});

Results will be received in RES variable as JSON Object. Lopp will read data from the object and print it in the console.

This code will give output as shown in the below screenshot.

 

Conclusion:

Hence, by following the above process you can now use API calls to fetch data from service into the instance variables and use it to make decisions related to the next steps in automation.Also the received data can be used as input in our next steps. I hope this will help developers looking for basic technical prerequisites and architectural skeleton to interface IRPA and ServiceNow.

Kindly comment your questions and feedback. 🙂

 

Best Regards,

Saurabh Chikate

2 Comments
You must be Logged on to comment or reply to a post.