LEAPWORK Learning Center

How to automate forms in ServiceNow

Written by Kasper Fehrend | Jan 14, 2019 2:52:01 PM

Working with ServiceNow is all about filling in forms and moving data across various states. Automating processes that involve these forms can be a real challenge. Here's how to easily do it with Leapwork.


Automatically filling out forms in ServiceNow with external data - whether it's for testing or process automation purposes - can seem like a technically daunting challenge. 

We've made a sample Leapwork automation flow for handling ServiceNow forms, along with a bunch of pre-made, out-of-the-box components, or sub-flows, specifically for ServiceNow automation. 

Instructions: Download and install the ServiceNow sample flows.

The "SNC Form Handler" component is especially useful for filling form fields with values using an external data source.

With the standard web automation components in the Leapwork Automation Platform, it's easy to capture a field and fill in a value one at a time. 

 

But what if there's a lot of fields to be filled, or if you're looking to maintain the inputted values in a data source, e.g. a spreadsheet, database or similar? In these cases, point-and-click UI automation still works, but using the SNC Form Handler component is much more efficient.

As demonstrated in the video tutorial above, the component accepts three parameters per field in the form:

  • Field type. The component comes with three default field types: 'Text', 'Searchable text', and 'Dropdown'. There are more field types in ServiceNow than these three, but once you've got the basics of this component, it's easy to add more field types.
  • Field label. This is the label in front of a form field, e.g. 'Priority' in a dropdown field containing several priority levels.
  • Field value. The value inputted to the field or item selected from the dropdown list.

Let's take a look under the hood of the SNC Form Handler component to understand its inner workings:

 

The three parameters mentioned are defined to the left and a Switch component handles the different Field Types. Depending on the Field Type, one of three embedded sub-flows are then triggered. For example, if the Field Type is "Text", then the "SNC Set Text Field by Label" sub-flow is triggered, passing two of the parameters, Field Label and Field Value, to the sub-flow. 

Going one step deeper, the component "SNC Set Text Field by Label" looks like this on the inside:

In this component, three things happen:

  1. The value of the “Field label” parameter is added to the Leapwork activity log to document that this label has been handled. This is purely for documentation purposes and has no functional purpose.
  2. Using the sub-flow “SNC Get Field Id from Label”, we transform the value of the “Field Label” parameter to a “Field Id”. In ServiceNow, all fields have a unique Id which is the best way to specify and interact with the fields. In most cases, the Id is not known by the user designing the automation flows, making it much easier to simply specify the label in front of the field instead.
  3. Once the “Field Label” parameter has been used to capture the Id of the field, the sub-flow “SNC Set Text Field by Id” sets the value of the text field using the captured Field Id and the value of the “Field Value” parameter.

Using external data sources when automating ServiceNow forms

As mentioned above, setting a field requires three parameters: Type, Label, and Value. 

Automatically filling a form with several fields is easily done by using the SNC Form Handler component in combination with an external data source, e.g. a spreadsheet, a database, a web service, etc. This way, the component provides the three parameters for each field in the form, and the data source provides the values to be inputted in the fields. When the automation flow is executed, Leapwork can iterate through all rows of data in the data source, if needed.

In the example below, the Leapwork component "Read Excel" is used for data-driven automation of a ServiceNow form.

First, we want to specify which data in the spreadsheet, we want to use. This is done with the "Select Range" functionality. 

Notice, that this data set contains three columns: Field Type, Field Label, and Field Value- each with seven rows of data. 

The column headers are used as input parameters for the SNC Form Handler component. With Leapwork, driving data this is simply done by visually connecting data sources to the component using the data as input. The connectors are the blue arrows in the screenshot below.

This is all there is to design a data-driven automation flow involving an Excel-file and a ServiceNow form. Note that the method 'Iterate' is selected, which means that  Leapwork will go through all rows of the selected data range, process them one at a time, and execute the SNC Form Handler component for each row of data.

Once all data rows have been processed and values have been applied in the ServiceNow form, the automation flow moves on to whatever action is next to be executed. 

Download and install the ServiceNow sample flows.

Everything you need for ServiceNow automation

Check out Leapwork's tutorials, out-of-the-box samples, and educational resources to get started with ServiceNow automation.

Or kick-off your ServiceNow automation with our whitepaper: