We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Must be member of group as well as group type to see edit button list control

Jalen Dixon
Tera Contributor

Hello, I am stuck trying to figure out why my script is not working. There are 2 set of groups. The first part works. The 2nd part is my issue - where I specify the type of group. This is how its supposed to work:

- If you are a member of the group and the group type is approval or support, show the edit button. Cannot get this to work for nothing. Please help. 

 

var answer = true;
var currentUser = gs.getUser();
var allowedGroups = gs.getProperty("property1");
var allowedGroups2 = gs.getProperty("property2");
allowedGroups = allowedGroups.split(",");
allowedGroups2 = allowedGroups2.split(",");

for (var i = 0; i < allowedGroups.length; i++){ // this part works fine
if (currentUser.isMemberOf(allowedGroups[i])){
answer = false;
break;
}
}

for (var j = 0; j < allowedGroups2.length; j++){ // this is the issue
if ((currentUser.isMemberOf(allowedGroups2[i]) && parent.type.indexOf('sysID of Approval type group') == -1) || (currentUser.isMemberOf(allowedGroups2[i]) && parent.type.indexOf('sysID of Support type group') == -1)){ // Group type is Approval or Support
answer = false;
break;
}
}
1 ACCEPTED SOLUTION

Anand Kumar P
Tera Patron

Hi @Jalen Dixon ,

Try below line using j instead of i in loop

if ((currentUser.isMemberOf(allowedGroups2[j])&& parent.type.indexOf('sysID of Approval type group') == -1) || (currentUser.isMemberOf(allowedGroups2[j]) && parent.type.indexOf('sysID of Support type group') == -1)){ // Group type is Approval or Support

 

Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand

View solution in original post

1 REPLY 1

Anand Kumar P
Tera Patron

Hi @Jalen Dixon ,

Try below line using j instead of i in loop

if ((currentUser.isMemberOf(allowedGroups2[j])&& parent.type.indexOf('sysID of Approval type group') == -1) || (currentUser.isMemberOf(allowedGroups2[j]) && parent.type.indexOf('sysID of Support type group') == -1)){ // Group type is Approval or Support

 

Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand