Help

Re: SUBSTITUTE is not a function

1747 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Ujval_Shah
5 - Automation Enthusiast
5 - Automation Enthusiast

let old = query[i].field_data;
let new = old.SUBSTITUTE(’\n’,’ \n’);

Results in “SUBSTITUTE is not a function”

5 Replies 5

It looks like you are writing a script versus writing an Airtable formula. Scripts are written in JavaScript, formula fields are written in Airtable’s formula field language. SUBSTITUTE is a function in the Airtable formula field language. It is not a function in the JavaScript language. You might want the JavaScript string function .replace().

You also need to make sure that you are using .replace() on the proper data type. It also seems like you are trying to replace a newline character with another newline character, which wouldn’t have any effect.

let old = query[i].field_data;
let new = old.replace(’\n’,’
’);

replace() does work but its working for the first occurrence only. I have a following string,


"One \n - Two \n - Three"

need this as,

"One </br> - Two </br> - Three"

If you want a JavaScript global replace you need to use a regular expression with the global flag.

Hi,
for those (like me) too lazy to learn regex for now, you can use split-join.
example, used in html txt parsing to get text from tag A to tag Z excluding all occurrences of tag X inside.

const cutter=(txt,pattern)=>txt.split(pattern).join(’’);
const cut=(txt,a,z,x)=>cutter((txt.split(a,2).pop().split(z,2).shift()), x);

but anyway, i’m going to start learning regex one day…

You can use the string .replace method with minimal to no regex knowledge. The webpage I linked to has an example of a global replace with static strings.