Eliminate Leading and Trailing Spaces in Fields - Catalog Client Script

alexcharleswort
Tera Expert

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.

1 ACCEPTED SOLUTION

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());  


View solution in original post

12 REPLIES 12

Joe McCarty1
ServiceNow Employee
ServiceNow Employee

Eliminate the .toString() and just have first.trim().   I think that should work for you.


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());


}


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());  


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!