TL;DR: I want to construct an array using JS and then pass that array to the input_select.set_options service-call data.
I’m trying to use the input_select.set_options service, which requires an array value for the options data. I can get it work fine if I use the dev tools and manually write an array like ["option 1", "option 2", "option 3"], but in NodeRed, if I try to pass an actual array object to the service call JSON, it injects all values into one input_select option.
What are you trying to do with {}"options:" "{{options}}" ?
If you wrap the {{}} in quotes you’re immediately turning that into a string; and not an array.
But I’m still not satisfied here, because my goal is to pass the array directly to the service call. Is there a way to format it that would work? My issue is that the array length varies, so I would need to have a service-call node for every possible array length…
Yep; the issue is that even if you pass an array to the data field via mustache template, it loads that array into a single option of the input_select. The 3rd screenshot in the original post demonstrates this.
Okay, I’ve figured out a way to get this to work, using JSONata expressions.
Instead of passing regular JSON to the service data, change it to a JSONata expression like this:
And then just write up any expression that won’t overly alter the data. I did $sort() in this case because my data was alphabetized anyway. It’s not the cleanest, but it works. If sorting the array is an issue, $distinct(array) will also work (while removing any duplicate entries).