Set variable based on incoming value

Hi, I’m new to n8n, and am trying to set a variable based on the value of an incoming variable.
Specifically, the variable ‘origin’ should be set differently depending on the incoming origin code.
For incoming value ‘Facebook ads’, origin should be set to ‘FB’
For ‘Chatbot’, should be set to ‘CH’
For ‘Buzzlead’, should be set to ‘RF’ and so on.
What would be the best way to do this?
Thanks a lot!

Welcome to the community @cdesseaux

Check the example below:

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      origin: 'Facebook ads'\n    }\n  },\n    {\n    json: {\n      origin: 'Chatbot'\n    }\n  },\n      {\n    json: {\n      origin: 'Buzzlead'\n    }\n  }\n]"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        490,
        300
      ],
      "notesInFlow": true,
      "notes": "Mockup Data"
    },
    {
      "parameters": {
        "functionCode": "switch (item.origin) {\n  case 'Facebook ads':\n    item.origin = 'FB'\n    break\n  case 'Chatbot':\n    item.origin = 'CH'\n    break\n  case 'Buzzlead':\n    item.origin = 'RF'\n    break\n}\n\nreturn item;"
      },
      "name": "FunctionItem",
      "type": "n8n-nodes-base.functionItem",
      "typeVersion": 1,
      "position": [
        690,
        300
      ],
      "notesInFlow": true,
      "notes": "Mapping"
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "FunctionItem",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Thanks a lot. That works perfectly. Another question (very basic, I’m afraid), if only one item would be received, there wouldn’t be a difference between using the function node and the functionItem node, correct?

There is a difference because they return the data differently.