Best answer

How do I turn multiple field values into a comma-separated string

  • 22 November 2021
  • 8 replies
  • 922 views

Userlevel 2
Badge

I’ve seen a ton of articles and posts on turning a comma-separated list into separate fields, but none on the opposite. I have text values in five different fields that come from columns in Google Sheets. I want to turn them into a comma-separated string to feed to my API. The challenge is that there isn’t always a value for all five fields, one or more can be empty.

So if I simply do Field1Value, Field2Value, Field3Value, Field4Value, Field5Value in the zap, and Field1 and Field 4 are blank, the result is extra commas like:

, Field2Value, Field3Value,, Field4Value.

Any ideas?

 

icon

Best answer by Troy Tessalone 22 November 2021, 23:31

View original

8 replies

Userlevel 7
Badge +14

Hi @jeffernst 

This can be done with a Code step: https://zapier.com/apps/code/help

Userlevel 7
Badge +14

@jeffernst 

Try this Code (JavaScript):

 

 

RESULTS

 

Userlevel 2
Badge

@Troy Tessalone just saw your sample, let me try with that.

Userlevel 7
Badge +14

@jeffernst 

See Code above.

Userlevel 7
Badge +14

@jeffernst 

Here’s another option

 

Userlevel 7
Badge +14

@jeffernst 

Did you get this to work?

Userlevel 2
Badge

@Troy Tessalone This worked perfectly, thank you so much, I will be using this in many zaps. You rock.

Userlevel 7
Badge +14

@jeffernst 

Consider using Sub-Zaps to share common Zap actions across other Zaps: https://zapier.com/apps/sub-zap-by-zapier/integrations#triggers-and-actions

 

 

Reply