Developing your story with tags

Creating IF statements to reduce the number of actions 

Sometimes triggers can add extra steps taking us farther from a result we may be looking for, but we still want to have some level of conditions. The most common place this happens is when using tags in an event transform action.

Tags allow us to create if statements to see if a value meets certain criteria. Tags are available when you click the "+" in the payload and go to "tags" instead of value. From there you'll see a variety of conditionals. The most common tag is using the if tag.

For example:

<%if SIZE(webhook.body.request) > 0%> "Is not empty" <%endif

💡Note

Tags require a beginning and ending:

  • <%if%> to start the condition

  • <%endif to end the condition

This applies to all tag types:

  • <%if%>...<%endif

  • <%for%>...<%endfor

We can reduce the number of actions needed in our story by using IF statements in an event transform action.

More info: https://www.tines.com/docs/formulas/language#tags 


IF statement breakdown 

This segment breaks down a bit more of the logic around using if statements and how to leverage basic tag examples. Typically in Tines, you'll find yourself using triggers to get most things done, but in some circumstances, we may need to use some tags. When we get to that point it's not bad for us to have a baseline of how these conditional if statements work.

An if statement allows you to execute code conditionally, based on whether a certain condition is true or false.

The basic structure is:

<%if (condition)%> 
  code to execute if the condition is true 
<%endif

The condition can be any expression that evaluates to True or False. If the condition is True, the information between the tags will be executed.

Example 1

<%if (5 > 2)%> 
  Five is greater than two! 
<%endif

This will print the statement "Five is greater than two!" because 5 is indeed greater than 2.

Example 2

You can have an else clause to execute code if the condition is False:

<%if (age >= 18)%> 
  You are an adult 
<%else%> 
  You are a minor 
<%endif

Here, if the age is less than 18, the else clause will be executed.

Example 3

You can have multiple conditions using elseif-else:

<%if (age < 13)%> 
  Child
<%elseif (age < 18)%> 
  Teenager
<%else%> 
  Adult
<%endif

Try it by copying the actions:

{"standardLibVersion":"34","actionRuntimeVersion":"4","agents":[{"disabled":false,"name":"Calculate Age","description":null,"options":"{\"mode\":\"message_only\",\"loop\":false,\"payload\":{\"Example 1\":\"<%if (5 > 2)%> \\n  Five is greater than two! \\n<%endif%>\",\"Example 2\":\"<%if (age >= 18)%> \\n  You are an adult \\n<%else%> \\n  You are a minor \\n<%endif%>\",\"Example 3\":\"<%if (age < 13)%> \\n  Child\\n<%elseif (age < 18)%> \\n  Teenager\\n<%else%> \\n  Adult\\n<%endif%>\"}}","position":{"x":-735,"y":765},"type":"eventTransformation","timeSavedUnit":"minutes","timeSavedValue":0,"monitorAllEvents":false,"monitorFailures":false,"monitorNoEventsEmitted":null,"recordType":null,"recordWriters":[],"form":null,"cardIconName":null,"createdFromTemplateGuid":null,"createdFromTemplateVersion":null,"originStoryIdentifier":"cloud:44d865a04582d77e2e3df773e8987d10:58105affb31970cabee71725f374ed90"},{"disabled":false,"name":"Age","description":null,"options":"{\"mode\":\"message_only\",\"loop\":false,\"payload\":20}","position":{"x":-735,"y":690},"type":"eventTransformation","timeSavedUnit":"minutes","timeSavedValue":0,"monitorAllEvents":false,"monitorFailures":false,"monitorNoEventsEmitted":null,"recordType":null,"recordWriters":[],"form":null,"cardIconName":null,"createdFromTemplateGuid":null,"createdFromTemplateVersion":null,"originStoryIdentifier":"cloud:44d865a04582d77e2e3df773e8987d10:58105affb31970cabee71725f374ed90"}],"links":[{"sourceIdentifier":1,"receiverIdentifier":0}],"diagramNotes":[]}

More info: https://www.tines.com/docs/apis/how-to-run-python-scripts-in-tines

Was this helpful?