cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to compose a condition with an if statement in workflows

wouterdt
Participant

Hi

i'm trying to figure out how the if statements work in conditions in workflows using this doc
 https://docs.dynatrace.com/docs/platform-modules/automations/workflows/reference#if-statement

I have a 3rd actions that should only fire when a value from the first actions and one from the seccond action equal a string.

I started off by just trying an if for the first action, but it never seems to trigger.

{%if result('action1').production == true %}
{% endif %}

a more simple version does work

{{result('action1').production == true}}

 

how do yo format that if statement?
does anyone have an example?

 

3 REPLIES 3

Eric_Yu
Dynatrace Mentor
Dynatrace Mentor

If your value is already a boolean, I don't think you need to use the "== true" part. Also make sure your result is being returned in the previous step.

 

Something like this should work:

Eric_Yu_0-1724795865894.png

Eric Yu | LATAM ACE Consultant

wouterdt
Participant

Currently it runs with the {{ variable == true }} without issue so you can use the true part

question is on on how to introduce a second variable and only proceed when 2 variables match a condition.
The  Jinja2 doc talks about if statements but i don't understand how to introduce them in this context.
The Dynatrace doc mentions if as well but does not show an example.
Tried stuff like this without much luck

{%if result('action1').production == true %}
{%if result('action2').priority == "P1" %}
{% endif %}
{% endif %}

ChristopherHejl
Dynatrace Advisor
Dynatrace Advisor

The custom condition field is essentially already wrapped in an "if" statement and you only provide the condition, as the action and else block are predefined.
As for combining multiple conditions, you'd use and, or and brackets () if needed.
Template Designer Documentation — Jinja Documentation (3.0.x) (palletsprojects.com)
example:

{{ result('action1').production == true and result('action2').priority == "P1" }}



Featured Posts