How to allow spaces before and after email IDs using regex expression?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2025 08:24 PM
Hello All,
I need some help from you.
I have a field called "u_email_addresses_for_targeted_email", I am adding some email id's with spaces and which is not sending emails whenever there is a space before or after the email id's.
Below is the script which is using in script include and calling on business rule.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2025 09:32 PM
your script include function has issue
Use this and fix the bold part
getRecipients: function ( current ) {
var parm3 = '';
var parm4 = '';
if ( current.u_publish_to_outage_portal_email_ta_dl == true ) {
parm3 = current.u_users_for_targeted_email.toString();
parm4 = current.u_email_addresses_for_targeted_email.toString();
parm4 = parm4.replace(/\s/g, '');
}
// these lines have issue, you don't have parm1 and parm2 defined anywhere but you are using it
var final_parm1 = parm1.toString() + "," + parm3.toString();
var final_parm2 = parm2.toString() + "," + parm4.toString();
var obj = {};
obj.final_parm1 = final_parm1;
obj.final_parm2 = final_parm2;
return obj;
},
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
02-04-2025 10:48 PM
Hello @Ankur Bawiskar,
Full code is not copied in chat but i am using the parm1 and parm2 in my script include.
Total script is copied below.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2025 11:16 PM
I already gave the line of code which will replace space between email
Did you try that?
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
02-04-2025 09:49 PM
parm4 = current.u_email_addresses_for_targeted_email.toString();
// Replace new lines with commas
parm4 = parm4.replace(/\r?\n/g, ',');
// Trim spaces before and after each email
parm4 = parm4.split(',')
.map(email => email.trim()) // Remove spaces before and after
.filter(email => email) // Remove empty values
.join(',');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2025 02:24 AM
@Ankur Bawiskar , Which lines i need to add in code?