Email script is not working

Mahalakshmi Rav
Tera Contributor

When the current caller id email ends with "@gmailusa.com", I need to send the notification to "USA tower" additionally. I wrote the email notification script as mentioned below but it's not working.

(function runMailScript(current, template, email, email_action, event) {

    var gr = new GlideRecord("sys_user");
    if (gr.get(current.caller_id)) {
        var callerEmail = gr.getValue("email");
        if (callerEmail.endsWith("@gmailusa.com")) {
            email.addAddress("to", "usatower@gmail.com", "USA Tower");
        }
    }

})(current, template, email, email_action, event);
 
MahalakshmiRav_0-1744100027716.png

 

 

MahalakshmiRav_1-1744099950862.png

MahalakshmiRav_1-1744100119061.png

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Shivalika
Mega Sage
Mega Sage

Hello @Mahalakshmi Rav 

 

 

I don't think you can modify the "TO" for any email notification using email script, you can modify "CC" and "BCC".

 

I had also tried this sometime back, I don't think this works. Try changing it to "CC" and see once, if the mail script is correct - with all the fields correct - it will definitely work. Else you might need to debug script. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

 

View solution in original post

6 REPLIES 6

Shivalika
Mega Sage
Mega Sage

Hello @Mahalakshmi Rav 

 

 

I don't think you can modify the "TO" for any email notification using email script, you can modify "CC" and "BCC".

 

I had also tried this sometime back, I don't think this works. Try changing it to "CC" and see once, if the mail script is correct - with all the fields correct - it will definitely work. Else you might need to debug script. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

 

Mahalakshmi Rav
Tera Contributor

Thanks @Shivalika for your suggestion, I tried changing to cc but still it's not working 

Hello @Mahalakshmi Rav 

 

In that case, go simple, use below mail script 

 

var gr = new GlideRecord("sys_user");
gr.addQuery('sys_id', current.caller_id.sys_id);
gr.query();
if(gr.next())
{ 
	var callerEmail = gr.getValue('email').toString();
	if(callerEmail.endsWith("@gmailusa.com"))
	{
		email.addAddress("cc", "usatower@gmail.com", "USA Tower");
	}

}

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

 

Also @Mahalakshmi Rav 

 

Remove the display value, just keep the email in CC

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY