Search code examples
javascriptnode.jszapier

I must replace some special characters on Code by Zapier


I need to replace some special characters on Zapier.

Since there are many substitutions, I want to do it through Code by Zapier.

I made the code, but I got the following error on Code by Zapier:

We had trouble sending your test through. TypeError: str.replace is not a function

Here is the code:

str = inputData;

str.replace(/Á|Ä|À|Ã|Â/g, "A");
str.replace(/É|Ë|È|Ê/g, "E");
str.replace(/Í|Ï|Ì|Î/g, "I");
str.replace(/Ó|Ö|Ò|Õ|Ô/g, "O");
str.replace(/Ú|Ü|Ù|Û/g, "U");

output = [{outputData: str}];

I don't know why str.replace doesn't work on Code by Zapier. I tried use str = str.replace(), instead str.replace(), but it did not worked too.

Can someone help?


Solution

  • Looks like inputData is not a string but rather an object. So if you provided a field to the Code then you need to access it as a property of that object. Let's say the name of the variable is foo, then you need to access it as inputData.foo.replace() (see screenshot).

    enter image description here