to check two or more specific values in array
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2022 04:49 AM
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
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2022 04:59 AM
Hi,
Try changing "!==" to "!="
Mark as correct and helpful if it solved your query.
Regards,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2022 01:11 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2022 05:03 AM
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
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2022 05:08 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader