How do I filter data from the AppState in a Text component

I am able to filter data from my AppState to show in a SmartTable with some JavaScript
return {{state.assessmentQuestions}}.filter(item => item.id == {{activeRoute.queryParams.questionId}})

With the Text component that does not seem to work. The Text field doesn’t seem to support JavaScript. Am I missing something or is there maybe a workaround to get filtered data into a Text component?

Hi @tim! Here’re the steps:

  1. Filter data the same way you did for a Smart table.
  2. Put that code in the “Code” step.
  3. Persist the result of the filter function in a separate variable.
  4. Bind this new variable to the text component.
1 Like

Hi @ev_jennie, thank you for the solution. That works.

Another option seems to be to use the filtering code as the sequence variable of the Text element. In my case the filter results to one element. I can then access the first element of the array and get the desired properties.

In the end I changed the data structure from an array to an object. This way I can access the desired element directly.

1 Like