I'm trying to write a query transformer that relies on data from a previous query:
// type your code here
// example: return formatDataAsArray(data).filter(row => row.quantity > 20)
const programs_custom_question_ids = {{ get_program.data.fields.custom_questions}}
//const programs_custom_question_ids = ["rec7RuWdgx85aI5UU","recpT1GD6gnqsEu3A","recvy87rX2DovnorF"];
return data.records.filter(row => programs_custom_question_ids.includes(row.id)).map(row => row.fields)
The query that has this transformer is manually triggered on success when the preceding query (get_program
) has completed. However since anything in {{}} is evaluated before the query / transformer runs, I get this error on page load:
Could not evaluate transformer in get_custom_questions_from_program: Error: Cannot read properties of null (reading 'records')
If I remove the {{}} and replace with a hardcoded array (see commented out line in transformer) there is no issue. I also tried adding some conditionals / optional chaining to no success.
Here are some related threads that describe this issue (without solutions):
- Issue with Transformer when referring to Query - #2 by alina.retool
- Referencing a temp state value in GraphQL query transformer fails
- How to create a transformer that transform some data based on other Firebase documents - #3 by Sylvain
- Best practice to access variable from transformer within {{}}?
What is the suggested approach here? Again, the transformer works as I need it to except for this erroneous error when Retool is attempting to evaluate the transformer before its needed. Thanks!