Conditionally display text in instructions or emails
In task instruction fields and the body of emails, you can set text to display conditionally based on the value of a field. This method uses field references and conditions to conditionally display text and fields.
To do this, you can write statements like this {{#if email-address}}{{email-address}}{{else}}{{phone-number}}{{/if}}
, which is equivalent to saying IF
an email address exists, THEN
display the email address, ELSE
(otherwise) display the phone number. These are called conditional statements, and use standard IF/THEN logic.
Here are a few more examples of conditional statements in real life:
IF
I’m hungry,THEN
I’ll eat an apple.UNLESS
It’s my turn,THEN
I’ll wait.IF
I’m tiredTHEN
I’ll rest,ELSE
(otherwise) I’ll keep studying.
How conditionally displaying text works
This feature works by checking to see if a field has any data in it, or exists at all. Depending on if the field does/does not exist, different text is displayed. You will use field references to form the above “statements”.
For example, to write an email to a customer that conditionally displays their email address (if it exists) or instead displays their phone number (if the email address does not exist), use IF
, and THEN
. Here’s the statement written as a conditional statement, then written using PagerDuty Workflow Automation’s notation.
IF
the users email address exists,THEN
it should appear,ELSE
(otherwise), the phone number should appear.{{#if email-address}}{{email-address}}{{else}}{{phone-number}}{{/if}}
Here’s an illustration of this concept in action:
How to write 3 types of conditional statements
IF statements
Use a single IF
to create a condition for text to appear if a field value does exist. If the field does not exist, nothing is shown.
{{#if field-name}}
This is the text will only display if field-name DOES exist
{{/if}}
More examples
IF / ELSE statements
Use IF
and ELSE
to create a condition for text to appear if a field value does exist and a second condition for different text to appear if the field does not exist:
{{#if field-name}}
This is the text will only display if field-name DOES exist
{{else}}
This is the text will only display if field-name DOES NOT exist
{{/if}}
More examples
UNLESS statements
Use UNLESS
to defining a condition for text to appear only if a field value does not exist:
{{#unless field-name}}
This is the text will only display if field-name DOES NOT exist
{{/unless}}
More examples
💡 Tip: If you have trouble configuring the conditions, you may need to set them in the previous editor. See How to open a step in the previous editor.
Get help with a problem or question
If something’s not working as expected, or you’re looking for suggestions, check through the options below.
Can I use an IF statement to check if a field equals a certain value?
Conditional if statements only work to check if a field exists or does not exist. It is not possible to use this method to check the actual value of a field.
As a workaround, you can set a field condition on a Text: Set value of a text field that will only execute if a field has a specific value. For example, to only show text if a Field A
is equal to Orange
:
- Use a field condition to check if
Field A
equalsOrange
. - If it does, use the Field: Set value of a text field action to set
Field B
toOrange
. - In your instructions or email body, add a conditional statement like
{{#if field-b}}This text only appears if Field A was set to Orange.{{/if}}
- If
Field A
was set to orange, thenField B
will exist and the statement will be true. - If
Field A
was not set to orange, thenField B
will not exist and the statement would be false.
- If
Will users see this conditional logic?
If you use this logic in an instruction field or email body, a user will never see the logic and will only see the result. PagerDuty Workflow Automation sorts through this logic and determines what to show, then shows it to users.
If this logic was used in a field that doesn’t support conditional statements, PagerDuty Workflow Automation will not sort through the logic and will leave it as is. Always test your actions and processes before using it in a live process.
The conditional statements are not working in instruction or email body fields.
If you have trouble configuring the conditions, you may need to set them in the previous editor. See How to open a step in the previous editor.
Thanks for your feedback
We update the Help Center daily, so expect changes soon.
Link Copied
Paste this URL anywhere to link straight to the section.