Iterate over context variable

Hi,

I am trying to iterate over a context variable passed as a string, and from there build a query to use in the dashboard blocks (Event list). Is there any way to do this directly using handlebars? or I should set up this query via workflow and pass the query via context. Using the template tester, I tried the following implementation, but without success.

This implementation would be to replace the use of

{"experienceuserId": {"$eq": "{{ctx.userId}}"}

which does not solve for more than 1000 devices. Any other suggestions?

You will need to build this query using a workflow and pass it through context.

The reason you can’t build this query using handlebars is because a string context variable is always just a string. In your example, you provided a JSON string, but there’s no way to know that it was supposed to be parsed into an array. To handlebars, that context looks like an ordinary string, not an array that can be looped over.

In the Template Tester Tool, the context you provided is assumed to always be JSON, so it’s automatically parsed into a JavaScript object.

This is, however, an interesting feature that’s worth exploring. Maybe a checkbox on the string context variable marking it as JSON so the dashboard knows to parse it into an object.

1 Like

Thanks @Brandon_Cannaday

Really, the possibility of passing a context variable as JSON would be an interesting feature.