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.

View solution in original post

7 REPLIES 7

Voona Rohila
Tera Patron

Hi @Shengavula Rath 

Try this

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.join();
},
type: 'AffectedCISubscribers'
});

 

Calling - 

javascript: new AffectedCISubscribers().AffectedCI();

Hi @Voona Rohila 

I just tried what u have mentioned above. But it is not working.

 

 

 

 

email client template : ShengavulaRath_0-1685951389936.png

 

Blank output 

ShengavulaRath_1-1685951488385.png

 

 

Hi @Shengavula Rath 

Can you keep logs in your script include and see the xyz value.

yeah I did that, I am getting expected list of emails. 

&

I am not sure in Bcc of email client template can we use script include or not.