Exist a better way to do this? “options dynamic population from external data”
i have found a workaround for dynamic population of options like that
on top the data from odoo populate options in second page of the form with this expressions:
{{
[
{
fieldLabel: "xxxx",
fieldType: "dropdown",
fieldOptions: {
values: $json.data[0].xxxx.map(entry => ({
option: entry.name
}))
},
requiredField: true
},
{
fieldLabel: "xxxx",
fieldType: "dropdown",
fieldOptions: {
values: $json.data[1].xxxx.map(entry => ({
option: entry.name
}))
},
requiredField: true
}
]
}}
Information on your n8n setup
**n8n version:1.68
**Database (default: SQLite):Postgress
n8n EXECUTIONS_PROCESS setting (default: own, main):
**Running n8n via (Docker, npm, n8n cloud, desktop app):Docker/Coolify
**Operating system:Linux
n8n
November 22, 2024, 4:14pm
2
It looks like your topic is missing some important information. Could you provide the following if applicable.
n8n version:
Database (default: SQLite):
n8n EXECUTIONS_PROCESS setting (default: own, main):
Running n8n via (Docker, npm, n8n cloud, desktop app):
Operating system:
barn4k
November 22, 2024, 10:27pm
3
hello @mredodos
that one is better
[
{
"fieldLabel":"xxxx",
"fieldType":"dropdown",
"fieldOptions": {
values: {{ JSON.stringify($json.data.map( entry => { return {option: entry.name} })) }}
},
"requiredField":true
}
]
1 Like
Thx do you know if i can put the name as the label show in front end and id as real value??
i think im missing something in your solution because return an invalid json
barn4k
November 26, 2024, 9:25pm
6
Can you provide a sample of the data?
It’s unclear what should be there
1 Like
About my question on set a label and value of options:
I need the ID of fields, but i need to populate the name inside the select too…
So i have found a workaround i have made a options like this name-ID
and after where i need the ID i have split and take last value {{ $(‘Form’).item.json.xxxx.split(“-”).last() }}
About your solutions, it seems to return always wrong JSON syntax at the end
my data output from the previus node before the secondo page form( the aggregator node) is like that:
[
{
"data": [
{
"Info": [
{
"id": 12,
"name": "Name 1"
},
{
"id": 17,
"name": "Name 2"
}
]
},
{
"Struct": [
{
"id": 1883,
"name": "name 1"
},
{
"id": 1868,
"name": "name 2"
},
{
"id": 1831,
"name": "name 3"
}
]
}
]
}
]
@barn4k sorry have you read my last message?
barn4k
December 6, 2024, 9:17am
9
You can do that directly in the form node, but the code will be quite complicated. Instead, it’s easier to build a json in the Code node
4 Likes
So from default n8n not support a options label/value in a dropdown?
barn4k
December 6, 2024, 9:31am
11
No, key/values are not supported there
1 Like
system
Closed
December 13, 2024, 9:32am
12
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.