Create and Update Incident (ServiceNow) - Jinja2 Templates
  • 18 Oct 2024
  • Dark
    Light
  • PDF

Create and Update Incident (ServiceNow) - Jinja2 Templates

  • Dark
    Light
  • PDF

Article summary

Before we begin building the lab exercise, we are going to look at Jinja2 Templates.  Jinja2 is a templating language developed for Python that allows users to take structured data and format it for human readability.  In our Create Incident with ServiceNow example, we will leverage a Jinja2 template to format text for ServiceNow, so this exercise will show you how to use variables and handle some logic in a Jinja2 Template.

Jinja2 Template Video

Step 1

From the IAP Dashboard, select Automation Studio.  From Automation Studio, click the + at the top of the left navigation panel, and the Create window will open.

Step 2

From the What would you like to create? dropdown, select Template.  Enter Template - XX for the Name, and Workshop for the Group.   From the Type dropdown, select Jinja2.   Click Create.

Step 3

A new template opens.  Using the sample JSON data provided below, update the Data on the left side of the screen.   

{
  "firstName": "",
  "title": "",
  "companyName": "",
  "repeatableTask": "",
  "vendorNames": []
}

Step 4

Using the sample template text provided below, update the Jinja2 Template on the right side of the screen.  Once both templates have been populated, the template will be parsed and the output is displayed in the Output area.  Click Save.

My name is {{ firstName }}, and I'm a(n) {{ title }}.
Here at {{ companyName }}, we would like to automate {{ repeatableTask }}.
{% if vendorNames | length == 1 %}
The most common networking vendor I work with is {{ vendorNames[0] | title }}.
{% elif vendorNames | length > 1 %}
The most common networking vendors I work with are:
{% for vendor in vendorNames %}
 - {{ vendor | title }}
{% endfor %}
{% endif %}

Step 5

Using the sample template text, update the template on the right side of the screen and see how the output changes below.

 Part of today’s workflow will leverage a Jinja2 Template in order to format text for ServiceNow, so this example will give you a better understanding of how that workflow operates.

 


 

 

 


Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.