- 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 08:58 AM
Eliminate the .toString() and just have first.trim(). I think that should work for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2017 09:02 AM
this did not 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.trim());
}

- 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 10:52 AM
well i am setting the variable 'first' to be what thirdparty_whofirst is.
You're script totally worked and that's awesome, thank you soo much!
But i do want to understand why i can't put 'first' as the setValue if it equals thirdparty_whofirst. Do you have a good way of explaining that? I just want to make sure that I don't have this problem in the future.
Again thank you so much!