- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2016 11:46 AM
I have a requirement that any [spaces] in a text field in a Service Catalog item be replaced with semi-colons (;). What's the best way to do this?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2016 11:10 AM
Use this one in onSubmit client script. not sure why it is throwing error in onChange.
function onSubmit() {
//Type appropriate comment here, and begin script below
var str = g_form.getValue('field_name');
var res = str.replace(/ /g, ";");
g_form.setValue('field_name',res);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2016 11:10 AM
Use this one in onSubmit client script. not sure why it is throwing error in onChange.
function onSubmit() {
//Type appropriate comment here, and begin script below
var str = g_form.getValue('field_name');
var res = str.replace(/ /g, ";");
g_form.setValue('field_name',res);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2016 12:34 PM
It's working now. I missed the additional var line.
How do you had multiple replacements? I'd like to also replace carriage returns with a semi-colon.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2016 12:46 PM
Here you go
var str = g_form.getValue('field_name').toString();
g_form.setValue('field_name',str.replace(/\s/g, ";"));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2016 06:53 AM
That did it, thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2016 07:00 AM
Never use / / as the pattern for space. Always used \s meta character to find all the white spaces.