Error when accessing data within a query transformer

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):

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!

Hello! Retool team, any help here? This seems like fairly straightforward functionality...

Hi @r0meboards, Happy to help here! You could move this script to a Run JS code query that runs on success of the previous query. Alternatively, you add logic to this transformer to account for the case where {{ get_program.data }} is null. I hope that helps!

Thank you! For future reference, the error was being triggered not by the item in the scope (get_program.data) but rather the data variable in the transformer itself. This resolved the issiue:

const programs_custom_question_ids =  {{  get_program.data.fields.custom_questions }};
    
if(data !== null) {
    return data.records.filter(row => programs_custom_question_ids.includes(row.id)).map(row => row.fields)
} else {
    return [];
}