Category: Widget
Resource links
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

Display Duplicate Options in a Select Widget

Issue

I am trying to display a select widget to pick an employee from my PostgresDB table, but I am facing an error due to duplicate values for name and surname. How can I solve this issue?

Resolution

The problem mentioned is that the select widget is returning an error due to duplicate values found for values that must be unique. This is because there are employees with the same surname and name in the table. To solve this problem, we can use the user_id column, which is unique, as the value in the label-value pair, and the name and surname columns as the label.

For example, we can use the following code to map the data from the QueryName object and create an array of objects with the label and value properties:

{{QueryName.data.map((item) => {return { "label": item.name + ' ' + item.surname, "value": item["user_id"]}})}}

This code creates an array of objects, where each object contains a label and a value property. The label is the concatenation of the name and surname columns, and the value is the user_id column.