- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2017 08:41 AM
Hi all,
I have a need to eliminate leading and following spaces in a field on a catalog item. I can get this to work nicely as a business rule for a table, but I would like to utilize this as a catalog client script on a form.
My string variable name is thirdparty_whofirst
I have tried an onSubmit catalog client script like this and it doesn't seem to work:
function onSubmit() {
//Type appropriate comment here, and begin script below
var first = g_form.getValue('thirdparty_whofirst');
g_form.setValue(first, first.toString().trim());
}
Let me know if you guys know where I'm and going wrong.
As always, thanks in advance for your help.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2017 09:07 AM
Whoops, you don't have your field name as the first parameter of setValue...Should have caught that...
Try
g_form.setValue('thirdparty_whofirst', first.trim());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2017 09:07 AM
Please try if this works
function onSubmit() {
//Type appropriate comment here, and begin script below
var first = g_form.getValue('thirdparty_whofirst');
first = first.replace(/^\s+|\s+$/g, "");
g_form.setValue("first", first);
}
Thanks
Please Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2017 09:09 AM
Will that script get rid of all spaces in the field? I dont want to get rid of all spaces, just any leading or following ones.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2017 09:11 AM
Leading and trailing spaces only, It is regular expression.
Just make sure you are setting it on the right field name. In your code the first just looked like a variable and not field name.
Thanks
Please Hit like, Helpful or Correct depending on the impact of the response