Oomnitza uses the Jinja2 templating language allow for a diverse array of transformations in order to better facilitate data management and hygeine, 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
- Update Block
- Notification and Approval block
- Conditional Threshold block
- Extended integrations
- Screen Builder
You can use Jinja2 to modify any Data Type (such as DateTime, Text, and Decimal).
However, when you are using the Update block, the data type must be set to text. This is because it is only possible to enter a Jinja2 in a text field. For information on creating these fields, refer to Creating custom fields.
Tip
Sometimes you'll want to ensure that data being retrieved is accepted as-is from the external system, such as 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}}.
Using Jinja2 in an API block
You can use custom Jinja2 in Oomnitza workflows to manipulate data and configure mapping. To create an API block workflow:
- Follow the steps in Creating workflows with the API block.
- In the Configure section of the API block window, select the Advanced Mode.
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 API 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.
Using Jinja2 in an Update block
When you select an Update block in a workflow, you can apply Jinja2 to a field you want to update. You can only enter Jinja2 template in a text field.
In the example below, the string operation{{tracking_number.replace('LX', 'XX')}}
is used in an Update block to modify the {{tracking_number}} field.
Figure 4: An example of a Jinja2 template in an Update block. The block will replace "LX" with "XX" according to the specified rules.
When the update block is triggered in a workflow, the record assigned to John Doe is updated with the values LX replaced with XX in the tracking number.
Figure 5: The updated user record showing the modification to the tracking number (LX004322) field
For additional information on Update blocks in Oomnitza, refer to Update block.
Using Jinja2 in a Notification or Approval block
When you select a Notification or an Approval block in a Workflow, you can add Jinja2 in the Message tab to customize the body of your message.
For additional information, refer to Notification block.
In the example below, the string operation zfill(10)
is used in a Notification 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 operators. For information on creating custom fields, see Creating custom fields in Oomnitza.
Figure 6: A string operation used in a text field in the Notification 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 notification 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
Using Jinja2 in a Conditional Threshold block
You can add a Jinja2 expression to a Conditional Threshold block in Advanced Mode. For information and examples, see Using the Conditional Threshold block.
Using Jinja2 when creating an 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 your integration is created, open the DateTime field in the Configuration > Data model menu, and in the Field information screen deselect the Add updates to History checkbox. Otherwise, the History tab will update every time the integration runs, which may serve to increase the integration run-time.
Using Jinja2 when customizing the 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, and then click Configure the view
.
- Select + Add Link to add a custom link to the top of the field grouping.
- Enter a Link 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.
Comments
0 comments
Please sign in to leave a comment.