Translate an element based on output

Describe the issue/error/question

I’m trying to change the output of a shipping code to match what another vendors is. Currently I’m using a switch outputting to a set for each then merging the (3 soon to be 4). However I then have to use the always send data option which the sets are then placing the translation in the output vs all nulls.

Is there a way to only have it translate if the data element exists and sends it through? Or will a code element need to be used, and if so could I get an example?

What is the error message (if any)?

Please share the workflow

Share the output returned by the last node

My last element in my CSV is currently: ,,,,,,,,,,,,,,,,,,,,,,,FDXSO,
due to one being empty, I’m trying to get it to be all null or preferrably not put any data in at all.

Information on your n8n setup

  • n8n version: Version 0.204.0
  • Database you’re using (default: SQLite): SQLite
  • Running n8n with the execution process [own(default), main]: Own
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: n8n.cloud

Hey @boardco,

Have you tried the code node? You could replace everything from the switch to the spreadsheet file with it.

Ended up using the following to solve this, thanks for pointing me in the right direction!

for (const item of $input.all())
  if (item.json.Mode_of_Delivery = "Economy") {
    item.json.Mode_of_Delivery = "FDXHD"
  } else if (item.json.Mode_of_Delivery = "STANDARD_OVERNIGHT"){
    item.json.Mode_of_Delivery = "FDXSO"
  } else if (item.json.Mode_of_Delivery = "FEDEX_GROUND"){
    item.json.Mode_of_Delivery = "FDXGR"
  } else {
     item.json.Mode_of_Delivery = "UNKNOWN"
  }
return $input.all();
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.