UI Dropdown - get result from SQL

So do what the sidebar says when formatting your msg.options value.

[{"Plant 13": 3}, ... ]

What if I'm taking the "label":"value" from the database?

It doesn't matter where you are getting the data from... You need to get it into the right format expected by the dashboard node.

You will need to write some Javascript in a function node to do it. Or use a JSONata expression in a change node.

I'm sorry, Nick. But, I'm unclear at the Change node part.


How to do the expression for "label":"value" here so that I'm able to save the value to the database instead of label?

If you aren't clear about the change node and JSONata, then write a JavaScript function to transform your data. I'm now out for the day.

Based on the screenshot of the data you have in this post - UI Dropdown - get result from SQL

You can either use a Function node with:

msg.options = msg.payload.map(function(value) {
    var v = {};
    v[value.location] = value.id;
    return v;
return msg;

Or a Change node, configured to "Set msg.options to the expression: $.payload.{location:id}

I tried as what you said. I had configured set msg.options to the expression: $.payload.{location:id} , but I'm getting the following error:


In which case your data is in a different format to what you said it is in. Or you have an entry in the database without a location property.

Did you try the Function node example?

I have location column in the database. I also tried function node example. Is said msg.payload.map is not a function.

If map is not a function then your payload is not an array.

So what steps are you going to take to debug this?

I had tried both methods, but still not working. Not sure what do next to make this work.

You need to check what your msg.payload contains. What node lets you examine a message?

1 Like

Hi Nick,

I added a Debug node after the Change node. This is what I can see after I deployed the flow:


How to make the dropdown working?

Thank for helping.

Hello, can anybody give me the export of the current state? It would be very grateful
cheers :slight_smile:

You have a different SQL query there compared to the previous screenshot.

You objects have properties locID and location. Previously you had id and location.

With these new property names, the Change node expression would be:


I already did it, but still the error coming up.


@rishanaziz in which case the message you have shown us in Debug is not the message you are passing the Change node.

Can you show us a screenshot of your flow that shows the sql node, debug node and change node?


You will have to narrow it down a lot. I don't see an SQL node there, so where is the query being done? Which are the relevant nodes here? Which Debug message is coming from which Debug node?

Your screenshot of the Debug sidebar now has two different messages - one of which is a number and one is an array. My guess is you are passing the message which is just a number to the Change node - which is why it doesn't work.

But until you explain your flow and highlight the relevant parts to us, its impossible for us to help.

I linked the SQL node to another tab. Here is the tab: