[Solved] Translate number to defined text for alerts


#1

I am attempting to create a workflow that takes a status code from our device {{data.Status}} and translates that to the text definition of the code for alerts via text or email.

I have set up a data table with two columns, Code and Code Description. I have been unsuccessful in using the device status to reference the description column that corresponds to the Status code.

I read about an option to use the switch logic to match the code to a text string - Is there a better way?

Thank you for your help.


#2

I think you’re on the right path. Data Tables are a great way to map status codes to text definitions. Here’s an example I put together to help answer this:

It’s got two status codes (100, 200) with text for each.

In the workflow, you can then use the Table: Get Rows Node to query your Data Table by the value of the incoming status code:

The results of the query, in the above screenshot, are put back on the payload at data.result. You can then access the results and the text column using the following template:

{{ data.result.items.[0].text }}

Using a Debug Node, you can inspect how Data Table results are placed on the payload:

So if you wanted to send an SMS with the status text, you could do something like:

Your device reported status with the following description:
{{ data.result.items.[0].text }}.


#3

Thank you very much! I was missing the template to access the text.

It is working now.


#4

Excellent! Glad we got it figured out.