- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-12-2022 10:13 AM
Hello,
How to get first word from the below data which is using the separator.
ex: Name|email from this I need Name which before the separator |.
Please help me on this one
Thanks!
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-12-2022 10:23 AM
Hi,
If you need first string from this data Please try below script you will get the first string.
var str="Name|Email";
var n=str.indexOf("|");
var firstword=str.substring(0,n);
gs.info(firstword);
Hope it helps!!
Please Mark ā Correct, Thanks!!
Regards
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-12-2022 10:23 AM
Hi,
If you need first string from this data Please try below script you will get the first string.
var str="Name|Email";
var n=str.indexOf("|");
var firstword=str.substring(0,n);
gs.info(firstword);
Hope it helps!!
Please Mark ā Correct, Thanks!!
Regards
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-12-2022 10:47 AM
var str = "Name|Email";
gs.info(str.split('|').shift());
This one also works if for some reason, sometimes str
will not contain the separator. E.g
var str = "Name Email";
gs.info(str.split('|').shift());
will print Name Email as apposed to an empty string. Though maybe that is not what is required?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-12-2022 11:45 AM
Here is the simple way
var str="Name|Email";
var name = str.split("|")[0].toString();
gs.print(name);
Mark the comment as a correct answer and also helpful if this helps to solve the problem.