Duplicate users Watch List

Sean Silveira
Tera Contributor

I added this to my inbound email actions to add users who are CC'd on an email to the watchlist of an incident/request:

current.watch_list = current.watch_list  + ',' +email.copied;

This works great, only issue is it will infinitely add duplicates to the watch list as emails are exchanged and people are cc'd.

Any ideas?

 

Here's the full script for reference:

gs.include('validators');

if (current.getTableName() == "incident") {
	
	current.watch_list = current.watch_list  + ',' +email.copied;
	
	var gr = current;
	
	if (email.subject.toLowerCase().indexOf("please reopen") >= 0)
		gr = new Incident().reopen(gr, email) || gr;
	
	gr.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;
	
	if (gs.hasRole("itil")) {
		if (email.body.assign != undefined)
			gr.assigned_to = email.body.assign;
		
		if (email.body.priority != undefined && isNumeric(email.body.priority))
			gr.priority = email.body.priority;
	}
	
	gr.update();
}
10 REPLIES 10

Allen Andreas
Administrator
Administrator

Hi,

You can change this line to:

current.watch_list = current.watch_list  + ',' +email.copied;

change to...

var u = current.getValue('watch_list') + ',' + email.copied;
var array = u.split(',');
var arrayUtil = new global.ArrayUtil();
var finalArray = arrayUtil.unique(array);

current.watch_list = finalArray.toString();

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Unfortunately this returned a similar result

 

find_real_file.png

Hi,

My apologies, I don't know how your script ended up looking.

Perhaps you could provide us with an update?

Please mark reply as Helpful, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Sure thing, appreciate the help.

 

gs.include('validators');

if (current.getTableName() == "incident") {
	
	var u = current.getValue('watch_list') + ',' + email.copied;
	var array = u.split(',');
	var arrayUtil = new global.ArrayUtil();
	var finalArray = arrayUtil.unique(array);

	current.watch_list = finalArray.toString();
	
	var gr = current;
	
	if (email.subject.toLowerCase().indexOf("please reopen") >= 0)
		gr = new Incident().reopen(gr, email) || gr;
	
	gr.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;
	
	if (gs.hasRole("itil")) {
		if (email.body.assign != undefined)
			gr.assigned_to = email.body.assign;
		
		if (email.body.priority != undefined && isNumeric(email.body.priority))
			gr.priority = email.body.priority;
	}
	
	gr.update();
}