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.

How to add cc'ed users in Watch list using inbound actions

SM_L
Giga Contributor

Dear All,

I've an requirement to add cc'ed users in email to watch list using inbound actions. it's working for me when i add a single user in cc, but if i had multiple users like 5 and all its not working.

Can someone help me on this. below is the code 

var userArray = [];
var copied = email.copied.split(',');
for (var i = 0; i < copied.length; i++) {
    gs.info("CC'ed email Address " + copied);
    var contact = new GlideRecord("sys_user");
    contact.addQuery('email', copied);
    contact.query();

    if (contact.next()) {
        userArray.push(contact.getUniqueValue().toString());
    }
    //current.internal_user = contact.getValue("sys_id");test
    current.short_description = email.subject;
    current.description = email.body_text;
    current.contact_type = "email";
    current.assigned_to = email.copied;
    current.watch_list = userArray.toString();
    current.insert();
}

 

Regards,

Suvarna

  

2 REPLIES 2

Murthy Ch
Giga Sage

hi @Suvarna

Try this:

var userArray = [];
var copied = email.copied.toString().split(',');  //changed here
for (var i = 0; i < copied.length; i++) {
    gs.info("CC'ed email Address " + copied);
    var contact = new GlideRecord("sys_user");
    contact.addQuery('email', copied[i]); //changed here
    contact.query();
    if (contact.next()) {
        userArray.push(contact.getUniqueValue().toString());
    }
}
    //current.internal_user = contact.getValue("sys_id");test
    current.short_description = email.subject;
    current.description = email.body_text;
    current.contact_type = "email";
    current.assigned_to = email.copied;
    current.watch_list = userArray.toString();
    current.insert();

Thanks,

Murthy

Thanks,
Murthy

SM_L
Giga Contributor

Hello Murthy,

It's only copying my name , but in cc i've added other 2 people name and its not populated in watch list.

find_real_file.png 

 

Regards,

Suvarna