📚 [Tutorial] Checking variable type

by Herman Semin

Version 1 (October 12, 2019)

Download (1,310 downloads)

Difficulty: easy (simple functions, 2 block/flow beginning)
Determine automate variable type with JSON encoding.

:: DISCLAMER ::
This is just a tutorial flow. I've used Variable Set's just to make explanation easier. More blocks = easier to understand how flow works.

So, since automate may be considered a scripting language (even though it's not really language), which is using dynamic typing, there has to be a way to check variable's type... Well, here's my solution.

Explanations (they are analogical for the other flow beginnings)
1. You set your variable in "Variable Set" (Block #3)
2. You cast json encoded value to string, then match it against integer-specific regular expression (string can only contain digits)
3. Result of regular expression matching is cast to boolean with double negation, so if variable type is integer, it returns 1, 0 otherwise.

4.9 average rating from 8 reviews

5 stars
7
4 stars
1
3 stars
0
2 stars
0
1 star
0
Reports
0

Rate and review within the app in the Community section.