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 = "email@example.com"
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.