Dropdown Perspective Using Query

Hello,
I’m trying to use a dropdown input on perspective. I need to get the data for it from a query in my database. Way different than Vision. I created a named query, but yeah :frowning: it does not work with the dropdown. Any easy method that you could recommend

Can you show the named query you are using and how you are binding it to the data property?

Believe you want to bind this to options, not value. Value is what is currently selected. Options are what they can select from.

Hi @Reyes,


Like say you need to bind to options.
I’ve done the same and my query return a value and label.
Make sure to set the return format to json.

Regards

You will also likely need a transform, since your return dataset has only one column.

E.G a script transform like:

	return [
		{
			"value": row
			"label": row
		} for row in value
	]
1 Like

Yes, after binding it to options I have all the data but some errors. I’m trying to add the transform that @PGriffith said, and I’m looking at the example that @De_Clerck_Arnaud showed. I really appreciate the help guys.

You haven’t added the transform.
Also expand options.0, etc., to see how the data looks. You should have something like

options
    0
        value: 1
        label: Option 1
    1
        value: 2
        label: Option 2

or, if the value and label are the same as in the transform,

options
    0
        value: 1
        label: 1
    1
        value: 2
        label: 2

set the return format to dataset if you use the transform script.
if you want to use json as return value then change your query to something like that.

Select name as label,
name as value
from qa_areas

2 Likes

It worked! Now it makes sense. You guys were giving me two ways to do that. @De_Clerck_ArnI I appreciate your help. Great forum. Thank you all.