Access Additional Scope Variables From OnSuccess/Failure

Took a while to figure it out, but it seems to be impossible to reference an additional scope variable from the OnSuccess/Failure events for Retool DB and OpenAPI queries. These are the only 2 resource types I've tried using doing this so I don't know if all resources are this way but, I'd guess they all are. Even though SQL mode lets you explicitly declare additional scope variables this still occurs with both SQL and GUI modes
image
image

the linter only shows a warning, but when it runs the debug window/dev tools shows an error similar to this:
image

is this intentional? I can't tell if it's on purpose or not so i used Feature Request and bug :man_shrugging:

You are trying to pass additional scope to a query (your first screenshot) and have the additional scope value persist to the success event (second screenshot) of that initial query, right?

It's an interesting idea - keeping the additional scope variables in scope (heehee) for the events. To work around it, I guess you could pass the variable into the SQL statement itself as a returned value (SELECT {{agentId}} as addl_scope_var, * ...) and then refer to the query result in the event instead of the variable (...userId: query.data[0].addl_scope_var vs userId: agentId)?

As to whether it should remain in scope :man_shrugging:

2 Likes

thanks a ton, that's perfect! It's def a workaround, but it's the first workaround I've seen that adds almost 0 extra overhead. I think these should be constant-time lookups at O(1) since no evaluation is done. Really couldn't ask for a better solution (other than directly using additional scope vars in events :innocent:)!

:beers: thanks again!

3 Likes