Dropdown node does not show query result when it is a array[1]

Hello forum,

I have a problem with the drop down node.
I make a query by SQL node to a Database table and I get the desired result. This result is then linked to a dropdown node, but I have a problem just in one case.
When the result of my query is an array with just one object like this:
immagine

in the dropdown list I don't see the result, like this:
immagine

while if the array contains more objects I don't have problem and see the list (result of my query).
The query works fine, the problem is in the shown dropdown list.

I pass data do the dropdown node in this way:

Do you have an idea of the origin of this problem?

Many thanks

Put a debug node after the change node (set to show complete message) - what do you see?

Then, compare your data to the example in the built in help of the drop down node, does your options match the required format?

Here it is the debug node result of change node
immagine

I see the array is not empty, but I don't see in the UI dropdown list

I followed this link

You did not set debug node to show complete message. I cannot see msg.options so you can't have compared it to the built in help.

When you use this JSONata expression:

$.payload.ID_Scad

it returns an array of values ONLY if there are more than one IDs found in the payload array. Otherwise it is flattened to a single value (as you found out the hard way). I'm guessing that the dropdown node is always expecting an array of values, instead of a single string, which is why it's blank.

To force your expression to always return an array, try appending square brackets like this...
(I removed the leading $. since it does nothing):

payload.ID_Scad[]

This causes any matching output to be returned as an array, so 1 or more values -- if nothing is matched, then nothing is returned.

The other syntax you can use is to wrap the entire expression in square brackets:

[payload.ID_Scad]

so even if nothing is found, you will get back an empty array -- FYI

As i said twice...

This will let us see what you are sending in msg.options to the drop down node.

And there is the problem - it is not an array.
image

JSONata expression payload.ID_Scad[] in change node should work.

If not, then a function node equivalent would be

msg.payload = msg.payload.map(e => e.ID_Scad);
return msg;

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.