Using replace in run script is not working

phoang
Kilo Expert

Hi,

I'm trying to replace spaces in my string with a comma within a Run Script in my workflow, but I keep getting 'undefined'.  This is what I've tried:

var copyNona3 = copyNona.replace(/,\s*$/, "");

var copyNona3 = copyNona.replace(/\s/g, ',');

var copyNona3 = copyNona.replace(/\s/g, ',');

But none of that worked.  I also joined a split().join() but that didn't work either.  

Can you use replace in a Run Script of a workflow?

 

Thanks.

Phuong

1 ACCEPTED SOLUTION

asifnoor
Kilo Patron

If you are getting undefined while calling replace, then copyNona might not be a string. Convert to string and then check it.

If you are getting undefined while printing copyNona3, thjen try this code

var copyNona2 = "Testing";
var copyNona3 = copyNona2.replace(/\s/g, ',');

Mark the comment as a correct answer and helpful if it helps.

View solution in original post

7 REPLIES 7

got it - need to put in string first...thanks!

asifnoor
Kilo Patron

If you are getting undefined while calling replace, then copyNona might not be a string. Convert to string and then check it.

If you are getting undefined while printing copyNona3, thjen try this code

var copyNona2 = "Testing";
var copyNona3 = copyNona2.replace(/\s/g, ',');

Mark the comment as a correct answer and helpful if it helps.

Aaaah yes that was it.  Thank you!