How to Populate a Text Field When Data Source Is Undefined


So I am building an app that takes a JSON file as input and then modifies certain properties in that file.

I am querying each field in my file and printing it in the app using this code: {{add_expression_text.value['3'].rhs}}. The problem is that when no data exists for such a field my ReTool app has a bunch of error messages showing “has an error in a property.”

The problem is that not all fields have values for all of the fields all of the time. How can I modify this code so that if the value is undefined it prints out nothing?

I have tried {{add_expression_text.value['3'].rhs || " "}} but that doesn’t work either.

Hi @boz01!

Answered this in chat support, but here’s the solution if others are stuck! Indexing into {{transform.value[1]}} when it was null caused an error inside the text component. So we added a null check, before trying to index: {{ transformer.value ? transformer.value['1'] : " " }}

1 Like

Hey, Ben, thanks so much for this answer. It works great after I import my JSON file. However, it doesn’t work when I first open the file; the fields still show an error?

hmmm what is the returned value of transformer before you import the file?

So I was able to fix this by adding the one-line JS logic like this:
{{add_expression_text.value != null ? add_expression_text.value['0'].lhs : "No Value"}}