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

**URL:** <https://discourse.nodered.org/t/dropdown-node-does-not-show-query-result-when-it-is-a-array-1/60325>\
**Category:** General\
**Created:** [25 March 2022 09:02 UTC](https://discourse.nodered.org/t/dropdown-node-does-not-show-query-result-when-it-is-a-array-1/60325 "2022-03-25T09:02:18Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![QGIO](https://avatars.discourse-cdn.com/v4/letter/q/f17d59/32.png) [@QGIO](https://discourse.nodered.org/u/QGIO)\
**Post date:** [25 March 2022 09:02 UTC](https://discourse.nodered.org/t/dropdown-node-does-not-show-query-result-when-it-is-a-array-1/60325/1 "2022-03-25T09:02:18Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/6/8643148f918888d9c52ddbda37aa34586f00688c.png)

in the dropdown list I don't see the result, like this:  
 ![immagine](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/1/d144c45183431cb972dc2db9ca70ecbeef1d91cc.png)

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:

 ![immagine](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/4/3470afe1dedc0c581b473a55d1ced990da3d4b51.png)

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

Many thanks

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 March 2022 09:13 UTC](https://discourse.nodered.org/t/dropdown-node-does-not-show-query-result-when-it-is-a-array-1/60325/2 "2022-03-25T09:13:40Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![QGIO](https://avatars.discourse-cdn.com/v4/letter/q/f17d59/32.png) [@QGIO](https://discourse.nodered.org/u/QGIO)\
**Post date:** [25 March 2022 09:18 UTC](https://discourse.nodered.org/t/dropdown-node-does-not-show-query-result-when-it-is-a-array-1/60325/3 "2022-03-25T09:18:59Z")

</div>

Here it is the debug node result of change node  
 ![immagine](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/1/a16f296be199dd2b6badc912c6f4ddb781d269e0.png)

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

---

<div class="post-metadata">

**Author:** ![QGIO](https://avatars.discourse-cdn.com/v4/letter/q/f17d59/32.png) [@QGIO](https://discourse.nodered.org/u/QGIO)\
**Post date:** [25 March 2022 09:29 UTC](https://discourse.nodered.org/t/dropdown-node-does-not-show-query-result-when-it-is-a-array-1/60325/4 "2022-03-25T09:29:06Z")

</div>

I followed this link

> [@UI Dropdown - get result from SQL](https://discourse.nodered.org/t/ui-dropdown-get-result-from-sql/614):
>
> Have some data from a MSSQL node that I want to insert as values in a Dropdown node, so I can return the selected value. But have searched high and low, but have not found and examble I can use Data… [{“Name”:“Name1”},{“Name”:“Name2”},{“Name”:“Name3”},{“Name”:“Name4”},{“Name”:“Name5”},{“Name”:“Name6”},{“Name”:“Name7”},{“Name”:“Name8”}]

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 March 2022 09:57 UTC](https://discourse.nodered.org/t/dropdown-node-does-not-show-query-result-when-it-is-a-array-1/60325/5 "2022-03-25T09:57:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [25 March 2022 11:17 UTC](https://discourse.nodered.org/t/dropdown-node-does-not-show-query-result-when-it-is-a-array-1/60325/6 "2022-03-25T11:17:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 March 2022 11:46 UTC](https://discourse.nodered.org/t/dropdown-node-does-not-show-query-result-when-it-is-a-array-1/60325/8 "2022-03-25T11:46:55Z")

</div>

> [@QGIO](#):
>
> but it doesn't work, when I have just one object I don't see it in the dropdown.

As i said twice...

> [@Steve-Mcl](#):
>
> Put a debug node after the change node (set to show complete message)

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

---

<div class="post-metadata">

**Author:** ![QGIO](https://avatars.discourse-cdn.com/v4/letter/q/f17d59/32.png) [@QGIO](https://discourse.nodered.org/u/QGIO)\
**Post date:** [25 March 2022 13:33 UTC](https://discourse.nodered.org/t/dropdown-node-does-not-show-query-result-when-it-is-a-array-1/60325/10 "2022-03-25T13:33:14Z")

</div>

![immagine](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/c/cc15d01ffa058f39f866417ebd03d089c54d8a8b.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 March 2022 13:40 UTC](https://discourse.nodered.org/t/dropdown-node-does-not-show-query-result-when-it-is-a-array-1/60325/11 "2022-03-25T13:40:26Z")

</div>

And there is the problem - it is not an array.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/9/594482673012e1d7ce9d0552b06d673adee50e59.png)

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

If not, then a function node equivalent would be

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

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [8 April 2022 13:40 UTC](https://discourse.nodered.org/t/dropdown-node-does-not-show-query-result-when-it-is-a-array-1/60325/12 "2022-04-08T13:40:55Z")

</div>

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