Split Contact in First and Last Name

adri
Giga Contributor

How can I split the field name (User Table), into First Name and Last Name fields? I only have a space betweek the first and last name to identify where to split it.

1 ACCEPTED SOLUTION

AshishKM
Kilo Patron
Kilo Patron

Hi Adri, 

Use the string split method on "name" field in sys_user table.

Check this code

var name = "ABC XYZ";
var splitName = name.split(' '); // use space as a delimiter 
gs.print('first name ->'+splitName[0]);
gs.print('last name ->'+splitName[1]);

 

Thanks,

Ashish


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

View solution in original post

4 REPLIES 4

AshishKM
Kilo Patron
Kilo Patron

Hi Adri, 

Use the string split method on "name" field in sys_user table.

Check this code

var name = "ABC XYZ";
var splitName = name.split(' '); // use space as a delimiter 
gs.print('first name ->'+splitName[0]);
gs.print('last name ->'+splitName[1]);

 

Thanks,

Ashish


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Hi Ashish,

could u pls help me on this:

In a string single field(Contact Name), we have the name "Priya Dubey"

now, this has to be print-like (pdubey) via email script. 

 

Regards,

Priya

Hi @Priya Gautum ,

You can use below email script.

var name="Priya Dubey"
var trunName = name.substring(0, 1)+name.split(" ")[1];
template.print(trunName.toLowerCase());

Hope it helps.

siva_
Giga Guru

There are multiple string manipulation techniques in javascript which helps you to solve various types of issues like this.

Please refer to string methods in w3schools under javascript thread.

Once you use split method in string manipulations it will load the values into the array based on what ever delimiter you have mentioned.

For ex : name = adri,servicenow

name.split(",") ---> results in name = ["adri","servicenow"]

in the same way we can have any character as a delimiter.

Thanks,

Siva