How to Include/Use Script Include in BCC field of Email Client Template ?

Shengavula Rath
Tera Expert

Hello Community!

Trying to use script include in the BCC of Email Client Template.

 

I am trying to autopopulate the some certain email addresses in Bcc Field of email client Template. For this I have written a script include and calling that script include in the bcc field as shown below. But this script include is not executing for some reason.

I am calling script include on bcc as below: 

javascript: new AffectedCISubscribers().AffectedCI();

 

Script Include:

var AffectedCISubscribers = Class.create();
AffectedCISubscribers.prototype = Object.extendsObject(AbstractAjaxProcessor, {

AffectedCI: function() {
var afc = new GlideRecord("task_ci");
afc.addQuery('task', current.sys_id);
afc.query();
var inc1 = [];
while (afc.next()) {
var inc2 = afc.getValue('ci_item');
inc1.push(inc2);
}

var nof = new GlideRecord("sys_notif_subscription");
nof.addQuery('affected_record', inc1);
nof.query();
var xyz = [];
while (nof.next()) {
xyz.push(nof.user.email);
}
return xyz;
},
type: 'AffectedCISubscribers'
});

 

I also tried changing the name of the function same as the script include name and then in Bcc I wrote this way

javascript: AffectedCISubscribers(); 

but even this didn't work.

 

Please let me know what changes I need to do to make this work.

1 ACCEPTED SOLUTION

Hi @Shengavula Rath 

Check these things

- If the Email client Template is on correct table or not.

- Also try by passing the sys_id as parameter instead of using current.sys_id.

- Add logs for inc1 and xyz and check the values.


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

View solution in original post

7 REPLIES 7

Hi @Shengavula Rath 

Check these things

- If the Email client Template is on correct table or not.

- Also try by passing the sys_id as parameter instead of using current.sys_id.

- Add logs for inc1 and xyz and check the values.


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Kamal17
Kilo Sage

Hi @Shengavula Rath ,

You can try the following steps on top of your/Voona's updated script.

1. Run this script in a fix script/background script with sample value instead of current.sys_id.

2. Add log statements to find the no of rows returned in each query. E.g., afc.getRowCount(), nof.getRowCount().

3. Add log statements to identify the values in inc1, xyz.

 

Most likely this issue could have occurred due to missing data. Above steps should help you to identify the root cause. Hope this helps!

 

 

Regards,

Kamal S

Ankur Bawiskar
Tera Patron
Tera Patron

@Shengavula Rath 

check this link

Scripting with Email Client Templates 

but this link says it's not consistent and not supported

Email Client Templates with "javascript:" tags on the To, CC, BCC or Subject are not supported 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader