Help on array / indexOf in script

Marcel H_
Tera Guru

Hoping someone can provide some guidance on an issue I'm trying to solve. I have a script in an inbound action that looks at recipients, puts them in an array and then looks for specific values. I thought I had found a way to look for multiple values in the array using indexOf, but couldn't seem to get it to work the way I thought it should. Is there a way in an indexOf check to check for value1 OR value2 OR value 3?

Below is my code. I ended up just looking for one of the values I needed (the most common) but there are times when people mail to one of the other addresses too. Any help is greatly appreciated!

//Note: current.opened_by is already set to the first UserID that matches the From: email address

var rarray = email.recipients.toLowerCase().split(",");
var nrarray = '';
var info1 = 'info@companyname.com';
var info2 = 'infocompanyname@companyname.com';
var info3 = 'instancename+ga@service-now.com';

for (var i=0; i<rarray.length; i++) {
	if (rarray[i] != info2) {
		if (nrarray)
			nrarray=nrarray+','+rarray[i];
		else
			nrarray = rarray[i];
	}
}
if (email.recipients.toLowerCase().indexOf('infocompanyname@companyname.com')>-1)
1 ACCEPTED SOLUTION

You can just add an OR

if (email.origemail.toString().toLowerCase().indexOf("@example.com") > -1 || email.origemail.toString().toLowerCase().indexOf("@company.com") > -1 )

View solution in original post

12 REPLIES 12

Correct, that should do it.  The "watchList" variable is being populated with a comma separated string, which that field is expecting.

I also have an Update inbound action script that runs at a lower order to capture updates, and it sets the Watch List too. I imagine that this could be simplified as well using the arrayUtil method?

 

if (email.recipients.toLowerCase().indexOf('infocompanyname@companyname.com')>-1)
	{
	if (current.watch_list!='' && current.watch_list.indexOf(email.origemail)==-1)
		current.watch_list = current.watch_list+','+email.origemail;
	else
		current.watch_list = email.origemail;
	
	if (current.getTableName() == "u_custom_table") {
		current.comments = "Reply from: " + email.origemail + "\n\n" + email.subject + "\n\n\n" + email.body_text.replace(/\n\n\n+________________________________+\n+CONFIDENTIALITY NOTICE:+.*/, '');

var rarray = email.recipients.toLowerCase().split(",");
var nrarray = '';
var info1 = 'info@companyname.com';
var info2 = 'infocompanyname@companyname.com';
var info3 = 'instancename+ga@service-now.com';
		
		for (var i=0; i<rarray.length; i++) {
			if (rarray[i] != info3 && current.watch_list.indexOf(rarray[i])==-1) {
				if (nrarray)
					nrarray=nrarray+','+rarray[i];
				else
					nrarray = rarray[i];
			}
		}
			
		if (nrarray!='')
			{
			if (current.watch_list!='')
				current.watch_list = current.watch_list+','+nrarray;
			else
				current.watch_list = nrarray;
		}
		current.update();
	}	
}

Correct.