Transfer text string into id via array / VLOOKUP

I want to transfer data from a trigger node to an application via HTTP-request. The trigger node provides the salutations like

  • Mr.
  • Mrs.
  • Company

as a text string. The receiving application expects a salutation id like “1” for Mr., “2” for “Mrs.” and “3” for “Company”. I thought about using an array with the possible values and applying something like VLOOKUP, but I was not able to find that.

What do you recommend?

I already managed it via Set node :slight_smile:

{{ $json.salutation[0] === "Mr." ? 1 : ($json.salutation[0] === "Mrs." ? 2 : ($json.salutation[0] === "Company" ? 3 : null)) }}

Hi @mokkin, welcome to the community!

There are a couple of approaches, but seeing you have only 3 possible options here I’d probably go with a raw n8n approach instead of writing any code. Here’s a quick example of how to use the Switch node and a couple of Set nodes for the job:

If you prefer a shorter workflow instead and don’t mind a little code, a close enough JavaScript replacement for VLOOKUP would be a switch statement. This can be used in a Code node. Here’s a quick example:

Each option would leave you with a new salutation_code field which you can then use in your subsequent workflow:

Hope this helps :slight_smile:

Edit: Just saw you already solved it, sorry :see_no_evil:

Don’t be sorry - thanks a lot for you help, even when I found a way by myself! :slight_smile: :+1:

1 Like

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