
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 01:21 AM
Hi ,
Arr=[abc@gmail.com,xyz@gmail.com,pqr@gmail.com]
I need to retrieve name from the given array list.
for eg: abc, xyz, pqr
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 02:15 AM
hi @Community Alums ,
try to run below script in background/fix script
var oldemail=['abc@gmail.com','xyz@gmail.com','pqr@gmail.com'];
var newarray=[];
for(var i=0;i<oldemail.length;i++){
var emails= oldemail[i];
var names=emails.split('@')[0];
newarray.push(names);
}
gs.info(newarray);
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
Thanks,
BK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 01:27 AM
Hello @Community Alums ,
Below is the code
// Array of email addresses
var emails = ["abc@gmail.com", "xyz@gmail.com", "pqr@gmail.com"];
// Array to hold the names
var names = [];
// Loop through each email
for (var i = 0; i < emails.length; i++) {
// Split the email at '@' and take the first part (the name)
var name = emails[i].split('@')[0];
names.push(name);
}
gs.info(names); // Output: ['abc', 'xyz', 'pqr']
Try running it in background.
Thanks,
Valmik Patil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 02:15 AM
hi @Community Alums ,
try to run below script in background/fix script
var oldemail=['abc@gmail.com','xyz@gmail.com','pqr@gmail.com'];
var newarray=[];
for(var i=0;i<oldemail.length;i++){
var emails= oldemail[i];
var names=emails.split('@')[0];
newarray.push(names);
}
gs.info(newarray);
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
Thanks,
BK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 02:30 AM
@Community Alums
this should be a simple one.
what did you try so far?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 06:40 AM
Hi Ankush, I posted this question because I attempted the same script but was not obtaining the desired results.
Thank you.