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-30-2022 05:28 PM
Thanks Ankur
i am doing well, thanks for suggestion as always ,its great advice .
just one thing with the above code, it works fine if either of the 2 specified sys_ids are Only selected but if i select another sys_id along with the specified one, it evaluates to false
["ea1d77f9dbf45110b8846c13059619e4","a6772fcddb04581818ca11b14a961990","e6772fcddb04581818ca11b14a9619be"]

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2022 01:12 AM
Share your updated code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2022 10:17 PM
Hi,
the ArrayUtil class function will check if the value you passed is present in that array or not
It should work fine in all the use-cases
I assume you want to search value of variable "secondary_access" in that roles list of sysIds
then it should work fine
share your updated script here
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
08-02-2022 04:57 AM
var curRec = new GlideRecord(advTABLE);
curRec.get(advRECORD); // advTABLE and advRECORD will be the reference to the record passed in from approval workflow
answer = getApprovers(curRec);
function getApprovers(ritm) {
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) {
// to return a group approver encapsulate the group in a JSON structure with type = group, and id = sys_id of the group as follows:
var rtnOb = {
type: 'group',
id: 'e89395f2db377010b8846c1305961955'
};
return rtnOb;
} else
return '';
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2022 04:52 PM
Hi Ankur
as per my updated script below still encounter this issue
I think its becoz the list collector items are truncated
e.g. 22772fcddb04581818ca11b14a961975,ea1d77f
Thanks
Levino