Create and Update Change Request (ServiceNow) - Jinja2 Template

Prev Next

Before we start building the lab exercise, we’re going to take a look at Jinja2 Templates. For those less familiar, Jinja2 is a templating language developed for Python that allows users to take structured data and format it for human readability. Here we’ll build a simple template that will show you how this is done. Part of today’s workflow will leverage a Jinja2 Template in order to format text for ServiceNow, so this small exercise will give you a better idea of how that workflow operates. 

Jinja2 Template Video

Step 1

From the IAP Dashboard, click Automation Studio

Step 2

Click the + at the top of the left navigation panel.

Step 3

The Create window opens. Click the dropdown and select Template

Step 4

Let’s give it a name of Template-XX and enter Workshop for Group.  For Type, click the dropdown and select Jinja2,

click Create.

Step 5

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

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

Step 6

Let’s use the sample template text found on the course resource document and paste in on the right.

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 7

Notice as we complete the form, how the output changes.

Step 8

We enter Jane for the first name and Network Engineer for the title.

Step 9

Company title is Acme Inc. We enter Change Management for Repeatable Tasks.

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