The CreatorCon Call for Content is officially open! Get started here.

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

dvp
Mega Sage

Can you uncomment //var email = new GlideEmailOutbound(); line and try again

jayachandra1
Kilo Contributor

Hi,

 

I have tried below 2 ways, but still not working:

Method 1:

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()
}
}

 

Method 2:

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var e = new GlideEmailOutbound();
if(!current.receives_a_copy.nil()){
var watcherIds = current.receives_a_copy.split(",");


//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()){

e.addAddress("cc", user.email, user.getDisplayValue());
//, user.getDisplayValue()
}
}

 

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

Can you replace addAddress line with

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