[Solved] How to use switch block?

Hi,

My device has a tag called “Type”. How can I use that in a switch block? I tried

{{data.myDevice.tags.Type}}

with no luck. Note that myDevice is populated correctly by a Get Device block. It contains my tags in an array, I can see them in the debug window but I don’t know how to use them in a switch block! I always get default case.

I also want to use one character in my payload in another switch block but I don’t know how to access that either! e.g. if my data.body.data = “1114”, I want to switch on the first character “1”. How can I do this?

Thanks

Ashley

For the tag lookup, check out the valueByKey format helper. Assuming your device is stored on your payload at data.myDevice, and you have not mutated the result to remove the tags, you would look up the value of the Type tag with the helper:

{{valueByKey data.myDevice.tags 'Type'}}

For isolating the first character of a string that is stored on the payloada at data.body.data, use this helper:

{{data.body.data.[0]}}

The 0 represents the character at position 0 (the first position); if you wanted to get the second character, you would switch the 0 to a 1 and so on.

We have some pretty detailed documentation on using helpers and payload paths to access data in your workflows. If anything is unclear here, please let us know so we can improve the docs!

Great, thanks for the help, I will give it a go. I never would have thought to put .[0] instead of just [0]!

Regards

Ashley