Search code examples
javascriptactionzapier

Zapier/Javascript - Code Action is formatting


GOAL

I have a form that sends multiple choice results as single line items and I'm using a Zapier Code Action to process and remove the blank entries:

WHAT I'VE DONE

Here's my sample data on Zapier Sample Data

This is my Javascript:

return {
  Movies: Object.values(inputData.Movies).join('\n'),
  Fruits: Object.values(inputData.Fruits).join('\n')
}

PROBLEM

My data is being turned into a giant vertical list of letters: enter image description here

Help, what am I doing wrong?


Solution

  • David here, from the Zapier Platform team. You're on the right track, but as the comment notes, you're joining a string. For reference, the input right now is:

    {
        "Fruits": "AppleBananaCocounut"
    }
    

    Instead, I'd set the input up with separators you know won't be in the input data (such as |). Then, you can parse the string into an array reliably.

    Input:

    code:

    const fruits = inputData.Fruits.split('|');
    return {filteredFruit: fruits.filter(Boolean)}
    

    This will result in an array (which you may want to join with a ", " so it looks nice later) of only the fruits that were present in the incoming data.

    ​Let me know if you've got any other questions!