Want to extract first two letters from first name and first three letters from last name to create UserId

avinashb
Tera Contributor

Hi All,

Can some one help me to extract first two letters from first name and last three letters from last name to create User Id upon submission of form.

Help is always appreciated.

Thanks and Regards,

Avinash balli

5 REPLIES 5

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

Here is an example:



var firstname = 'John';


var lastname = 'Wayne';



var user = firstname.substring(0,2) + lastname.substring(0, 3);



gs.print(user);



With results:



[0:00:00.004] Script completed in scope global: script



*** Script: JoWay

Hi Sergiu,



A slight modification, it should be first three letters from last name:


  1. var firstname = 'John';  
  2. var lastname = 'Wayne';  
  3.  
  4. var user = firstname.substring(0,2) + lastname.substring(0,3);  
  5.  
  6. gs.print(user);  

Hi Sergiu,



From last name I need last 3 letters.


Use this then:



var user = firstname.substring(0,2) + lastname.substring(lastname.length - 3, lastname.length);