'Zapier Javascript Find/Replace Special Characters
I am passing order data from Shopify to VimeoOTT using Zapier. We have been doing this for a year and it works great, except when the customer's name has special characters in it. For example "Jack & Jill (tumble)" The & or ( parenthesis ) causes an error that stops the process.
I am trying to use Zapier's Javascript Action to find and replace the name data's special characters, but I keep getting a coding error. This is my first time working with Javascript :(.
This image shows the Zapier Code Action
Here is an image showing the error I get
// this is wrapped in an `async` function
// you can use await throughout the function
nameFix = inputData.nameFix.replace(/[^a-zA-Z0-9 ]/g,'_').replace(/_{2,}/g,'_');
output = [nameFix];
Solution 1:[1]
In javascript, variables must be declared before they are used using let
or const
:
const nameFix = inputData.nameFix.replace(...
So, that'll fix the error you're seeing.
Separately, JS steps in Zapier must return an object (which has keys and values). So, you'll want to return the result like so:
return {result: nameFix}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | xavdid |