- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2019 03:07 AM
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.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2019 03:50 AM
Can you replace addAddress line with
email.addAddress("cc", user.email.toString(), user.getDisplayValue());

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2019 03:13 AM
Hi
You can check this once :-

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2019 03:32 AM
Can you uncomment //var email = new GlideEmailOutbound(); line and try again
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2019 03:45 AM
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2019 03:50 AM
Can you replace addAddress line with
email.addAddress("cc", user.email.toString(), user.getDisplayValue());