How can I access a component dynamically using its ID (string) from query14.data.id to call setValue with event run script? Is there a Retool API or method like components[componentId] to achieve this?
Just double checking if you are referring to the query's result properly by adding the index either on data or id, depending on whether is structured as an array or not, i.e.
The preferred approach to this would be to have a mapping object containing the id string and a pointer to the component. That can become hard to maintain, though, and dynamic fields within a listview etc are often easier to work with.
Can I ask what your use case is here and what outcome it is you're trying to reach?
I'm trying to convert the value from the text input to Title Case, and instead of querying each component separately, I tried to build a dynamic structure.
As an event, I want to take the identity and value of each component as variables and pass them to the js query created for the title case, and I want to do this with as few queries as possible. Then, I want to set the new value for the component with the same identity.
It's been a little while now, @nsrdl, but I thought I'd jump in and summarize everything that has been discussed above.
Although unconventional, using eval is far and away the simplest solution for turning a component ID into the corresponding object pointer. The typical dangers associated with this approach are somewhat mitigated by the fact that the resulting JS executes in a locked-down sandbox environment, but it's still not ideal.
In a perfect world, Retool would expose an object with key-addressable references to all canvas components. To @dcartlidge's point, it's certainly possible to build this yourself but maintaining it would quickly become cumbersome.
I'll log a request for a native solution, but am not necessarily convinced that the use case you've described requires something that complex. How is the non-titleized value of each input being set?