How to remove spaces in a catalog item variable ?

Jo Chatterjee
Giga Expert

Hello I have requirement, wherein if a user types in the variable (select box) - "this is a test name" then it should display as "thisisatestname" in the RITM and task. I have written the below simple code but doesn't work.

OnSubmit Client script

function onSubmit() {
//Remove spaces from the field
var first = g_form.getValue('variable1');
g_form.setValue('variable1',first.trim());
}

1 ACCEPTED SOLUTION

Murthy Ch
Giga Sage

Hi @Jo Chatterjee 

Instead of trim use replace method.

Thanks & BR,

Murthy

Thanks,
Murthy

View solution in original post

6 REPLIES 6

Brad Bowman
Kilo Patron
Kilo Patron

Hi Jo,

The trim method only removes any leading and trailing spaces in a string.  Instead, try the replace method

g_form.setValue('variable1',first.replace(/ /g, ''));

Murthy Ch
Giga Sage

Hi @Jo Chatterjee 

Instead of trim use replace method.

Thanks & BR,

Murthy

Thanks,
Murthy

Jo Chatterjee
Giga Expert

Hi Brad, Murthy, thank you for your responses. I tried replace too, but no difference.

var first = g_form.getValue('variable1');

var trimnm = first.replace(/ /g, '');
g_form.setValue('variable1',trimnm);

 

Didn't work

 

Hi @Jo Chatterjee 

 

Try this

var first = g_form.getValue('variable1');

var trimnm = first.split(" ").join("");
g_form.setValue('variable1',trimnm);

 

Let me know, if it worked

Please mark my answer as correct /helful, if your issue is resolved