to check two or more specific values in array

levino
Giga Guru

hi there

roleVar is a list of sys_ids.

roles is the specific sys_ids i want to check and if found do something.

 

when i try with the  first sys_id it evaluates correctly , but not with the second one, is the script below correct?

 

Thanks

Levino

 

 

 

 var roleVar = ritm.variables.secondary_access.toString();
    var roles = 'ea1d77f9dbf45110b8846c13059619e4,f96d773ddbf45110b8846c130596197c';



    for (var i = 0; i < roleVar.length; i++) {
        if (roles.indexOf(roleVar[i]) !== -1) 
{
//do somethin
}
11 REPLIES 11

SumanthDosapati
Mega Sage
Mega Sage

Hi,

Try changing "!==" to "!="

 

Mark as correct and helpful if it solved your query.

Regards,
Sumanth

Feel free to reach out if you have further questions or else you can mark an answer as correct and helpful to close the thread so that it benefits future visitors also.

Regards,
Sumanth

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

ServiceNow has given you ArrayUtil class and you can search using it easily instead of iterating

Take the benefit of that and it works in both global + scope app

ArrayUtil - Global

var roleVar = ritm.variables.secondary_access.toString();
var roles = 'ea1d77f9dbf45110b8846c13059619e4,f96d773ddbf45110b8846c130596197c';

roles = roles.split(',');

var arrayUtil = new global.ArrayUtil();

var isPresent = arrayUtil.contains(roles, roleVar);

if(isPresent){
	// do something
}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@levino 

Hope you are doing good.

Did my reply answer your question?

If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader