Replace Field Value using Regex

carlocsa
Kilo Expert

Hi!

I have a field containing a string. For example "servicenow guru". I want to remove the space between "servicenow" and "guru" upon submitting the record.   The value after submit should be "servicenowguru"). How to do this in a catalog client script?

Thanks!

Carlo

1 ACCEPTED SOLUTION

If it is on client script;


var variable = g_form.getValue('variable name');


var variable1 = variable.toString().replace(/\s/g, '').trim();  


g_form.setValue('variable name',variable1);


View solution in original post

8 REPLIES 8

lSurya 24
Giga Guru

Hello carlo,



You need to write an onchange cleint script, if you want user to know that spaces will be removed after he enters.


And also, you can onafter business rule if it is table form.


If it is on client script;


var variable = g_form.getValue('variable name');


var variable1 = variable.toString().replace(/\s/g, '').trim();  


g_form.setValue('variable name',variable1);


Thanks budy!

vab_13
ServiceNow Employee
ServiceNow Employee

This should do the trick:


=====


if(current.field1.indexOf(" ") >= 0)


        var replaced = current.field1.split(' ').join('');



=====




Mark your feedback( Like or Helpful or Correct) as per the impact of my response. Cheers!


Vab