Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Inbound action for adding CC and BCC to watchlist no longer working?

Amulville
Tera Contributor

I have been using this script for over a year and it has recently stopped working for adding people that were cced or bcced to the watchlist. 

 

Here is my code: 

var wList = current.watch_list;
var gList = current.u_group_watch_list;
var rarray = email.recipients_array;
var instanceEmail = gs.getProperty('glide.email.user');

//iterate through the recipient array
for(var i = 0; i < rarray.length; i++) {
    var recipient = rarray[i];

    var gr = new GlideRecord('sys_user');
    gr.addQuery('email', recipient);
    gr.query();
   
    if(gr.next()) {
        //it's a user
        if(wList != "") {
            wList = (wList + ',' + gr.sys_id);
        } else {
            wList = gr.sys_id;
        }
    } else {
        if(recipient != instanceEmail) {
            if(wList != "") {
                wList = (wList + ',' + recipient);
            } else {
                wList = recipient;
            }
        }
    }
}
current.update();
 
fairly straightforward, I am going through the email and iterating through the recipient array, checking this against the sys_user table and adds them(either by email or by sys_id). 
1 REPLY 1

Amulville
Tera Contributor

I found out what my problem was I needed this around my code 

(function runAction(/*GlideRecord*/current, event, email, logger, classifier) {
 
})(current, event, email, logger, classifier);