Drop Down - 2 Values

I have a drop down that is displaying a value from a SQL query. Is there a way to get 2 values per row in the drop down?
With databases, there is the human readable value and the "ID" of that value.
For example, if I had a SQL statement that pulled a list of Students ID and their Name, I would get values like:
1 Bob
2 Ahmad
3 Kala

My goal is to have the user pick the "Name" but, in a variable, store the ID so that I can use that to now grab additional data to display such as their age, a list of classes they have attended.

To get around this, I am doing multiple passes to the database to find what I need which is very inefficient.

Ideas?

You can send all the values from each array element if you wish.
You can send as an object (works fine for simple objects, not to large), or you can send as string and convert to an object after selection.
example of both.

[{"id":"e171772c0bc3477d","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"d_waarde\":1,\"d_max\":2,\"d_min\":3,\"name\":\"bob\"},{\"d_waarde\":2,\"d_max\":2,\"d_min\":3,\"name\":\"bill\"},{\"d_waarde\":3,\"d_max\":2,\"d_min\":3,\"name\":\"ben\"}]","payloadType":"json","x":110,"y":1440,"wires":[["80fcc958bb9ba4aa"]]},{"id":"80fcc958bb9ba4aa","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"options","pt":"msg","to":"$$.payload.{$.name: $}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":1440,"wires":[["ab2e9a2804ad7892","78c8edc889f86bd0"]]},{"id":"ab2e9a2804ad7892","type":"ui_dropdown","z":"452103ea51141731","name":"","label":"","tooltip":"","place":"Select option","group":"2d4fe667.28f8ba","order":17,"width":0,"height":0,"passthru":false,"multiple":false,"options":[],"payload":"","topic":"topic","topicType":"msg","className":"","x":420,"y":1480,"wires":[["78c8edc889f86bd0"]]},{"id":"78c8edc889f86bd0","type":"debug","z":"452103ea51141731","name":"debug 100","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":550,"y":1440,"wires":[]},{"id":"1b82aa02021d95e8","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"d_waarde\":1,\"d_max\":2,\"d_min\":3,\"name\":\"bob\"},{\"d_waarde\":2,\"d_max\":2,\"d_min\":3,\"name\":\"bill\"},{\"d_waarde\":3,\"d_max\":2,\"d_min\":3,\"name\":\"ben\"}]","payloadType":"json","x":90,"y":1560,"wires":[["8211356b5dd309f5"]]},{"id":"8211356b5dd309f5","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"options","pt":"msg","to":"$$.payload.{$.name: $string($)}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":240,"y":1560,"wires":[["9b692f6a668f10e2","c59484177b4c27b8"]]},{"id":"9b692f6a668f10e2","type":"ui_dropdown","z":"452103ea51141731","name":"","label":"","tooltip":"","place":"Select option","group":"2d4fe667.28f8ba","order":17,"width":0,"height":0,"passthru":false,"multiple":false,"options":[],"payload":"","topic":"topic","topicType":"msg","className":"","x":400,"y":1600,"wires":[["67131e8b3bfb70a5"]]},{"id":"67131e8b3bfb70a5","type":"json","z":"452103ea51141731","name":"","property":"payload","action":"","pretty":false,"x":550,"y":1600,"wires":[["c59484177b4c27b8"]]},{"id":"c59484177b4c27b8","type":"debug","z":"452103ea51141731","name":"debug 101","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":630,"y":1560,"wires":[]},{"id":"2d4fe667.28f8ba","type":"ui_group","name":"demo","tab":"1caa8458.b17814","order":2,"disp":true,"width":"12","collapse":false},{"id":"1caa8458.b17814","type":"ui_tab","name":"Demo","icon":"dashboard","order":1,"disabled":false,"hidden":false}]
$$.payload.{ // $$ (msg context).payload.(map each element to $ context) { (create object)
   $.name: $string($)  // $ ($ context).name (object property name): $string($) ( set property value to $ context but convert to string)
} // Close object, map next element

Super cool!
Not sure how it works..but I do see that the output is the entire payload. Just have to reverse engineer y our example to try and understand it.

Thank you so much!!

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