- 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 10:56 AM
The g_form.setValue function has 2 parameters, the first of which is the field you are modifying and the second is the value.
On the server, if your are doing something like current.field_name.setValue('value') that setValue function on GlideElement objects related to a GlideRecord only has 1 parameter because the field is implied.
Hope that makes sense.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2017 11:02 AM
right. so I set: var first = g_form.getValue('thirdparty_whofirst)
so in the g_form.setValue I put 'first' because that is the field I am setting and then I am setting it with first.trim() which is a modified version of thirdparty_whofirst.
is it just a general rule that you can't assign a value to a variable and then reference that variable in the first parameter when it requires two?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2017 11:07 AM
Not entirely sure I follow. Do you have a Catalog Item variable named 'first' (distinct/different from a client script variable)?
The first parameter needs to be a catalog form field (catalog item variable) with that name, not a client side javascript variable (defined with the var keyword in script).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2017 03:29 AM
Hi Joe,
I'm trying the same in a OnChange Catalog Client Script:
var mobile = g_form.getValue('mobile_phone');
g_form.setValue(mobile, mobile.trim());
But it's not working, what am I doing wrong?
Im trying to remove "spaces" in the mobile number. So if it's like "+45 66 00 000 000" it will be "+456600000000".
Best regards,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2017 03:34 AM
The first parameter in the line :
g_form.setValue(mobile, mobile.trim());
should be a string identifying the name of the field to set, i.e.:
g_form.setValue('mobile_phone', mobile.trim());
Whereas you are trying to find a field with a name equal to the value of the variable mobile.