ArrayUtil indexOf/contains not working

Rachel55
Mega Guru

Hello.  I am trying to create a script for a login rule.  I am testing in backgroud scripts.  The script is supposed to look for a specific role for the logged in user.  Without the if statement, the array will print, and I can see that it contains itil. When the if statement is added, it gives the error message "Javascript compiler exception: Java class "[Ljava.lang.String;" has no public instance field or method named "size". (sys_script_include.fb32a2d8c0a80a6000e907036f484b5b.script; line 61) in:".  I get the same error whether I am using "contains" or "indexOf".

 

var arrUtil = new ArrayUtil();

var u = gs.getUser();

var myArray = u.getRoles().toString().split(",");

if (arrUtil.contains(myArray, "itil")){

gs.print("yes");

}

for (i=0; i<myArray.length;i++) {

gs.print(myArray[i]);

}

12 REPLIES 12

Rachel55
Mega Guru

Ok.  Thanks

 

Ian Mildon
Tera Guru

See if this helps. I just tested this in Scripts - Background and it accurately printed the response depending on the role I checked on.

var arrVal = [];
arrVal = gs.getUser().getRoles();

var thisRole = "itil";

if(arrVal.contains(thisRole)) {
    gs.print("We have a match");
}   else {
    gs.print("No match");
}

I tested as is (which matched) then I purposely checked on a role I don't have and it correctly printed "No match"