email.addAddress() is not working for scoped application

jayachandra1
Kilo Contributor

We are trying to use email.addAddress() method for adding "Receive a Copy" field in CC of email notification.

When i use static value in cc like below format, emails are sending to CC:

email.addAddress("CC", 'test@gmail.com");

Whereas if i use dynamic values like below, emails are not triggering to CC, instead i am getting warning:

Warning:

java.lang.RuntimeException: failed to coerce com.glide.script.fencing.ScopedGlideElement to desired type java.lang.String
Caused by error in Email Script: 'AddReceiveaCopy' at line 17

14:
15: while(user.next()){
16: gs.info(user.email+'display value');
==> 17: email.addAddress("cc", user.email);
18: //, user.getDisplayValue()
19: }
20: }

 

Email Script:

var watcherIds = current.receives_a_copy.split(",");
//var email = new GlideEmailOutbound();
//get user records
var user =new GlideRecord("sys_user");
user.addQuery("sys_id", watcherIds);
user.addQuery("notification",2);
//email
user.addQuery("email","!=","");
user.query();

while(user.next()){
var emailaddress = user.email;
email.addAddress("cc", user.email, user.getDisplayValue());
//, user.getDisplayValue()
}
}

 

can anyone help me on this issue.

1 ACCEPTED SOLUTION

Can you replace addAddress line with

 email.addAddress("cc", user.email.toString(), user.getDisplayValue());

 

View solution in original post

5 REPLIES 5

sathishk
Mega Contributor

Hi,

I'm also trying to add recipients in bcc. my email script is in scoped app.

per your recommendation, added the following 

var email = new GlideEmailOutbound();
email.addAddress("cc", user.email.toString(), user.getDisplayValue());

but I don't see the BCC is added in the email logs.

(function runMailScript(current, template, email, email_action, event) {
var em = new GlideEmailOutbound();
var recip = event.parm1.toString().split(',');

for(var i=0;i<recip.length;i++){
var user = new GlideRecord('sys_user');
user.addQuery('email',recip[i]);
user.query();
while(user.next()){
em.addAddress("bcc", user.email.toString());
}
}

})(current, template, email, email_action, event);

 

Can anyone please help me out...