Describe the issue/error/question
This might be complicated to explain, but I’ll do my best!
I am trying to process data captured through a form. The form JSON payload may (or may not!) contain responses in some fields.
What I’m currently doing is splitting out the fields that are ‘required’ (I know these will have responses) and those that are optional - using Set, to two different payloads. I have 4x optional attributes. Basically, I want to transform the value of each field in this payload, if it exists. If it does not exist, it should be ignored.
What I currently have (below) works when all fields are populated. When some of these optional fields are empty, the merge will force the previous node to execute so I’ll get the additional transform text that I want, but without the value.
My logic is -
- If the ‘Company’ field is populated, manipulate it. Otherwise, delete the company field.
OR - If the ‘Phone’ field is populated, manipulate it. Otherwise, delete the phone field.
OR
— etc.
I’ve tried to process this linearly - using Set to remove the field that should be vacant, then feeding it to the next condition. The challenge here is that both a true and false condition on ‘company’ would I think need to form the input to the if for ‘phone’… which means that the company field, if previously removed, may get added back.
There has to be a better way to do it, I’m just stuck on how to do it.
I’d love to be able to do this without using ‘Merge’.
What is the error message (if any)?
Please share the workflow
This is the part of the workflow in question.
Share the output returned by the last node
Current output:
[
{
“ps_company”:“-Company “My Company””,
“ps_phone”:“-MobilePhone “””,
“ps_enddate”:“-AccountExpirationDate “,
“ps_strengths”:”-OtherAttributes @{info=“One | Two | Three | Four | Five”}”
}
]
Desired output (“Phone” and “End Date” fields from earlier should not be processed):
[
{
“ps_company”:“-Company “My Company””,
“ps_strengths”:“-OtherAttributes @{info=“One | Two | Three | Four | Five”}”
}
]
Information on your n8n setup
- n8n version: 0.204.0
- Database you’re using (default: SQLite): SQLite
- Running n8n with the execution process [own(default), main]:
- Running n8n via [Docker, npm, n8n.cloud, desktop app]: Docker