- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2019 12:51 PM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2019 01:02 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2019 12:53 PM
Are you sure there are spaces in the string? The following works fine in the console:
var copyNona3 = copyNona.replace(/\s/g, ',');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2019 01:02 PM
Yes I've tried spaces and returns and getting undefined. The log shows the data from variable and it's how I entered but then after using the replace it's undefined. My full script:
var copyNona = current.variables.asset_copy_non;
gs.log('copyNona: ' + copyNona);
var copyNona1 = copyNona.replace(/\s/g, ',');
//var copyNona3 = copyNona.replace(/,\s*$/, "");
gs.log('copyNona1: ' + copyNona1);
current.variables.nonSL=copyNona1;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2019 12:57 PM
This works fine testing as a background script:
var copyNona = "This is a Test";
var copyNona3 = copyNona.replace(/\s/g, ',');
gs.print(copyNona3);
Does copyNona have spaces in it or even data in it? Usually undefined means nothing is in the variable or maybe it doesn't have spaces. You should be able to do that in a run script in a workflow.
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2019 01:01 PM
The log shows data from the variable:
copyNona: test1 test2
But still shows undefined.
My full script:
var copyNona = current.variables.asset_copy_non;
gs.log('copyNona: ' + copyNona);
var copyNona1 = copyNona.replace(/\s/g, ',');
//var copyNona3 = copyNona.replace(/,\s*$/, "");
gs.log('copyNona1: ' + copyNona1);
current.variables.nonSL=copyNona1;