This article explains how LEAPWORK can be integrated with ServiceNow to create incidents when automation flow fails.
Before we start, please make sure you have below prerequisites ready for integration.
- HostName or IP Address and API port of LEAPWORK Controller should be known to the user.
- The user has an API Access key for a given LEAPWORK Controller.
- All flow need to be executed are organized in a Run List
- The run-list is scheduled using the LEAPWORK scheduler and the schedule name is noted.
- User must-have service now credentials with API calling access.
- Basic understanding of PowerShell or coding.
Step by step process
The LEAPWORK public REST API makes it very easy for DevOps, IT operations, and developers to integrate LEAPWORK with any third-party system. This article will instruct you on how to automatically create incidents in ServiceNow when automation flows in LEAPWORK fails.
As a part of the integration, we have a Windows PowerShell script that runs a pre-defined LEAPWORK run list, polls for the results until they are available, and then loops through all failed cases and creates incidents in ServiceNow using API.
Please follow the below steps to achieve the required integration for your environment:
Step 1: Download the attached Integration PowerShell script and open it in your preferable editor. We are going to use the Windows PowerShell ISE editor to update the script.
Step 2: The first two things you need to change in PowerShell Script is the Controller hostname and the controller port. The script has localhost as the hostname and default port 9001 as a port. In order to point the script to call your controller endpoints, the user has to update the values of these two global variables viz. $controllerHostNameOrIPAddress and $controllerPort.
Step 2: Next, you need to set service now credentials and the URL of your instance to the PowerShell script. The below variables need to be supplied value.
$serviceNowUser = "username"
$serviceNowPass = "password"
$serviceNowInstance = "https://yourdomain.service-now.com"
$incidentOwnerEmail = "firstname.lastname@example.org"
Step 3: Create an API access key in LEAPWORK Controller and note it down (refer: Preconditions, point number 2). Once you have the Access Key, you can go to the Powershell script and replace the generated key with the Access key value in the header section as shown below
Step 4: Verify that the flow you want to run are there in the Run list and the Runlist has a Schedule associated with it (refer: Preconditions, point number 3 and 4), Make a note of the Schedule name and replace the Schedule name in Powershell with the name of schedule you have.
Step 5: Run the Powershell script
When you run the PowerShell script, the schedule will be executed and for failed flows, incidents will be logged in ServiceNow as described below.
- First of all, the value of the variable will be assigned to global variables
- Afterward, RunScheduleAndGetResults Method will be called which will call the LEAPWORK API endpoint to execute the schedule and polls for the result until that is available.
# Run the LEAPWORK schedule "My Test Schedule" and get the results.
$runResult = RunScheduleAndGetResults($scheduleName)
- Once the result is available, the script will try to find the number of the failed cases. If the number of failed tests is greater than zero then it will start collecting logs and screenshots. Finally, it will call the service now endpoint recursively i.e. in a loop for logging the incidents.
- Service now endpoint will file incidents on service now until all of them are logged.
Here is how an incident logged by the above script looks like in service now.
Please note that the script contains no error handling or logging mechanisms. It is meant only to demonstrate the core functionality of integrating LEAPWORK with ServiceNow.
For any clarification, please contact our Priority Support.