I’d like to modify a form entry. Let me explain: in one of my forms, I detailed a training choice. However, to add the data to my baserow database, I need to return my primary field.
So I added a “set” node and, using AI, I created this json:
{
“Training_Code”: {
“value”: “={{ $node[‘Form’].json[‘Choose your training’] === ‘Canine and Feline First Aid – Initial Cycle’ ? ‘PSCF-ini’ : ($node[‘Form’].json[‘Choose your training’] === ‘Canine and Feline First Aid – Retraining’ ? ‘PSCF-Recyl’ : $node[‘Form’].json[‘Choose your training’]) }}”,
“mode”: “set”
}
}
However, it doesn’t return the dynamic solution, but everything between the " " in the “value” section. Where am I going wrong?
My goal is for it to return “PSCF-ini” if the answer to the “Choose your training” question on the form is “Canine and Feline First Aid – Initial Course” and “PSCF-Recyl” if the answer is “Canine and Feline First Aid – Retraining”.
Currently, I only have two possible answers, but I will eventually have more.
If it helps, both pieces of information are in the “Training” table on Baserow.
Thank you for your help.
Sincerely,
Information on your n8n setup
**n8n version: I have a self-hosted n8n on a VPS, version n8n 1.104.1 (Self-Hosted).
In n8n Set node, you don’t need “{{ }}” and quotes at the same time. You just set the value field to an expression. Currently, the quotes make it behave like a string of text, not an expression. Here is how you can fix it:
{
"Training_Code": "={{
$node['Form'].json['Choose your training'] === 'Canine and Feline First Aid – Initial Cycle'
? 'PSCF-ini'
: ($node['Form'].json['Choose your training'] === 'Canine and Feline First Aid – Retraining'
? 'PSCF-Recyl'
: $node['Form'].json['Choose your training'])
}}"
}
Also, here is how you can make it scale better in the future, when you add more values, using a lookup object:
={{
(function() {
const map = {
'Canine and Feline First Aid – Initial Cycle': 'PSCF-ini',
'Canine and Feline First Aid – Retraining': 'PSCF-Recyl',
};
return map[$node['Form'].json['Choose your training']] || 'UNKNOWN';
})()
}}
Let me know if this helps or if I can assist further
A quick follow-up question: I have a new step in my form where I need to display all open sessions for registration. These sessions are in a table in the baserow database. I configured a baserow get many node to retrieve all open sessions. How can I now display them in a dropdown list field in my form?
No worries, if the previous one works for you, don’t forget to tag it as the solution to help others in the future : )
Now, for the forms question, I would have to get a better understanding of your workflow. Can you submit a new question (to keep things organized), with
your exported workflow JSON (if possible)
screenshots of the data output of the from the DB
screenshots/details on the form you are using and the nodes for it (if not visible in export)
I can answer there with more suggestions after I review them.