Oomnitza uses the Jinja2 templating language to allow for a diverse array of transformations in order to better facilitate data management and hygiene, as well as complex functions and data transformations.
Using Jinja2 in Oomnitza
You can use custom Jinja2 in the following locations in Oomnitza:
- API block
- Conditional Threshold block
- Nested workflow block
- Notify and Decision block
- Oomnitza block
- Update Block
- Extended integrations
- Screen Builder
You can use Jinja2 to modify any Data Type (such as DateTime, Text, and Decimal).
Tip
Sometimes you'll want to ensure that the data being retrieved is accepted as-is from the external system, such as in cases with dates and phone numbers that use the '-' symbol to separate numbers. In these cases, values may be interpreted as math equations instead of strings. To prevent this, "| as_is" can be added to the template to interpret the field as a raw input. For example: {{phone_number | as_is}}.
API block
While in the Advanced Mode of the API block, you can add custom Jinja2 to the following locations:
- In the URL field in the Information tab.
- In the URL query parameters in the Params tab.
- In the HTTP headers in the Headers tab.
- In the message body in the Body tab.
- In the Response field in the Response tab.
Figure 1: An example of a Jinja2 template used in the Response field where the asset id in the API response is mapped to the Oomnitza ID field. Refer to Check if a field is defined (exists) for more information.
Figure 2: An example of Jinja2 template used in the API URL field to delete a user. The identifier of the user is used to form the URL path.
Figure 3: An example of Jinja2 template used in the Body tab to convert the weight of a package to pounds.
Conditional Threshold block
You can add a Jinja2 expression to a Conditional Threshold block in Advanced Mode.
Nested workflow block
You can add a Jinja2 to modify or alter nested workflow variables in the Nested workflow block.
Notify or Decision block
When you select a Notify or a Decision block in a Workflow, you can add Jinja2 in the Message tab to customize the body of your message.
In the example below, the string operation zfill(10)
is used in a Notify block to modify the {{tracking_number}} field. The tracking number field is a custom field created in Oomnitza with data type = text and contains the value LX004322. A text field is required to perform string operations.
Figure 6: A string operation used in a text field in the Notify block
The zfill(10)
operation returns a copy of the string left filled with'0'
digits to make a string of length 10. When the notify block is triggered in a workflow, the generated email output displays the eight-character tracking number with two additional zeros prepended:
Figure 7: The generated email output showing the modification to the tracking number (LX004322) field
Oomnitza block
You can add custom Jinja2 to the following locations:
- In the value field in the Path params.
- In the message body in the Body tab.
- In the Response field in the Response tab.
- In the HTTP headers in the Headers tab.
Figure 1: An example of a Jinja2 template used as a path parameter. The identifier of the serial number is used to form the path.
Figure 2: An example of Jinja2 template used in the Body tab to modify string values and perform calculations
Figure 3: An example of a Jinja2 template used in the Response field. Text that appears before the comma is extracted and mapped to the First Name field.
Update block
When you choose an Update block within a workflow, you can implement Jinja2 code by opting for the Coding feature.
Using the Coding option in the Update block
Extended integration
You can use Jinja2 when specifying the mapping in an extended integration. For example, you could use Jinja2 to add a timestamp to a field every time an integration runs:
- Go to Configuration>Integrations>Overview.
- Select an existing integration or create a new one.
- In Mappings, click the Add button in the Connector section.
- Enter a Field name, for example, Last Sync Time, and in the Field path enter the following Jinja2 statement:
{% set datetime = import('datetime') %}{% set rightnow = datetime.datetime.utcnow()%}{{rightnow}}
- Map this to a DateTime field in Oomnitza. When the integration is created, open the DateTime field and deselect Add updates to History. To do this, click Configuration > Data Model > Field Configuration, click the field, and deselect Add updates to History. If left selected, the History page for each record will be updated every time the integration is run. This might have a negative impact on the integration runtime.
Screen Builder
You can use Jinja2 in the Screen Builder to construct a custom URL that directs you to an external website. For example, you can use the Serial Number of an asset to construct a URL path.
- Click a record, such as an asset record
- Click the Actions menu .
- Click Screen Builder
- Click+ Add Link
- Enter a label, for example, Open in AWS.
- Enter your Link followed by the field name you want to use to construct the link:
https://www.yourdomainhere.com/exampleaction?{{serial_number}}
Figure 8: An example of a Jinja2 template link created using the Screen Builder. The link is visible in every asset record and directs the user to an external website, with part of the URL query coming from the {{serial_number}} variable.
Linking records to external websites
Comments
0 comments
Please sign in to leave a comment.