ServiceNow orchestration provides a workflow engine to manage processes and automate things outside of ServiceNow instance.
Note: One should have basic knowledge of ServiceNow Orchestration and REST.
In ServiceNow Orchestration, activity designer is used to create custom activities. It enables user to construct reusable activity according to organization’s business requirement.
The User should have workflow_admin or activity_creator role to create custom activity.
Following are the customizable activity templates to create and manage custom activities.
Let’s understand the creation of a REST activity. For demo, create a REST custom activity to make user in JIRA where JIRA is an open source Project Management tool.
NOTE: JIRA API information is available on the link provided below: https://developer.atlassian.com/cloud/jira/platform/rest/
Step 1: Create REST message to consume JIRA created user API:
Name: Name of the REST message.
Description: Provide short description.
Endpoint: API of the tool (JIRA) that one wants to consume.
In Authentication tab:
- Authentication Type: Select the authentication type:
2) OAuth 2.0
- Basic Auth Profile: Select the basic profile that is created.
In HTTP Request Tab:
- HTTP Headers: This means that one will accept the ‘application data’ in JSON format and ‘content type’ will be JSON.
In HTTP Methods:
Now create HTTP methods of GET and POST to perform create or post operations.
Click on New:
- REST Message: It will populate automatically.
- Name: Name of the method.
- HTTP Method: POST
- Endpoint: It will be automatically populated.
In HTTP request:
- HTTP Headers: This implies that one will accept the ‘application’ data in JSON format and ‘content type’ will be JSON.
- Select appropriate mid server, if required.
- HTTP Query Parameter: Provide query parameters.
- Content: Provide the data to create user in JIRA.
Now, click on auto-generate variables and test. 201 is the success code if the test is successful.
Step 2: Now let’s create custom activity:
In navigator search for orchestration ->workflow editor and open the workflow editor.
Click on Custom tab ->to create new custom activity click on (+) ->REST web service Activity.
Multiple tabs are available in the activity. Let’s discuss them sequentially.
- Name: Name of the activity
- Execution Template: This is read-only field depending on the chosen template.
- Short Description: Provides short description of the activity.
- Application: Global.
- Accessible from: Select the scope from which activity will be accessible.
- Description: Provide description and click on continue.
Here, one can define information which will be given by the end user to create user. These are called as input variables. In below example, let’s take input from end user as their Name, Password, Email Address, and Display Name.
- Name: Name the input variable
- Type: Select variable such as string, Boolean, Integer, Decimal, Object.
- Mandatory: Select YES, if you want to make this variable mandatory or else NO.
- Default: Mention the default value of the variable.
Click on Continue.
EXECUTION COMMAND TAB:
In execution command tab, one maps the input variables with workflow activity values.
- REST Message: Search and select the self-created rest message.
- REST Message Function: Select the method created earlier in HTTP Methods (POST or GET).
- Endpoint: Mention the Endpoint.
- Variable Substitution: Map input variables with activity values. Just drag and drop the inputs from INPUTS to Value. This enables to map activity inputs to respective rest message.
- Timeout: Specify time limit for trying to connect to the API in seconds.
- Authentication: There are multiple options available for using credentials. According to organizational need, one can select one of the available options.
- Here, let’s select ‘Use Existing Credentials in REST message’. Now, it will use the credentials mentioned in REST message.Click on continue.
In this tab, the variables in the output stage will be mapped to parameter values of REST test payload.
In this scenario, let’s take ‘Key’ as the output variable and drag and drop it into variable name in ‘Parse Rule’ section.
In Post-Processing, one can write scripts to handle/format the incoming data using script. For example, validation of the data.
Now click on the variable name of the ‘Parse Rule’ section. In this section, one needs to write parsing rule for output variable.
- Parsing Source: Select the source for parsing. Here, let’s parse the Result body.
- Parsing Type: There are 4 types of parsing:
Here, JSON parsing type is selected.
- Sample payload data: Place the sample payload data.
Hint: One can get the sample payload data by using POSTMAN tool. Try to consume the JIRA rest API in postman and get the result body after success.
- Expression: Select any of the variables in sample data payload e.g ‘Key’. Automatically, its expression gets created in expression tab.
- Click on test expression. This will parse that particular expression and will give result in ‘Parsing result’.
Click on submit.
In condition tab, specify the conditions that workflow will require such as success, failure.
In any workflow defined, there should be at least 1 exit condition defined as ‘true’ otherwise workflow will not end and will get stuck. Workflow engine will always evaluate all false conditions based on order, then it will process true condition.
In this scenario, the workflow will be successful only if it gets the output key as not null i.e. it satisfies activity.Output.key!=null condition.
On failure, workflow will end with else condition ‘true’.
Step 3: Now click on Test Inputs:
Fill the test values and check the status. Also, check in JIRA whether user got created or not.
This is how one can create custom test activity in ServiceNow orchestration.
Let us see the same activity in workflow with small example.
For demo, first create a catalog Item where user can fill the information.
We hope this blog has helped you in understanding Service Now Orchestration with custom REST activity in an efficient way.