first 3 characters

kpj
Giga Contributor

Hi All,

I am trying to populate name field on another field through client script. But I want only first 3 characters to be auto-populated. Please share your thoughts on how to achieve this?

Appreciate you Help!!

Thank you,

Jack

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi Jack,



You would do something like this with an onChange client script on field1.



var str = g_form.getValue('field1');


g_form.setValue('field2', str.substring(0, 3));



Modify 'field1' to be the name of your source field and 'field2' to be the name of your target field.


View solution in original post

4 REPLIES 4

Chuck Tomasi
Tera Patron

Hi Jack,



You would do something like this with an onChange client script on field1.



var str = g_form.getValue('field1');


g_form.setValue('field2', str.substring(0, 3));



Modify 'field1' to be the name of your source field and 'field2' to be the name of your target field.


kpj
Giga Contributor

thanks Chuck!! its working



Can we also remove special characters?


Geoffrey2
ServiceNow Employee
ServiceNow Employee

You can do that with a .replace() function using a regular expression.



str = str.replace(/[^a-z0-9]/gi, ''); // strip out anything that's not a letter or number


Geoffrey2
ServiceNow Employee
ServiceNow Employee