Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

how to check if array only has "A" or "B" or "A and B" ?


I want to check if the user is only in either Users and/or Watchers role .. I  have this working but wondering if there is a more elegant way ? 

if ( (remoteUsersRoles == ["Users"]) || ( remoteUsersRoles == ["Users","Watching"] ) || ( remoteUsersRoles == ["Watching", "Users"] ) )

Thanks in advance 

2 answers

0 votes

Another approach to achieve what Nic suggested is:

def rolesToCheck = ['Users', 'Watching']
if( rolesToCheck.any{it in remoterUserRoles})

With 2 roles to check, it's not bad, but should you have a situation with a log more, having a bunch of OR groups would be tedious.

But if you desire to check if the user has some other roles or not, you can do it this way:

def rolesToCheck = ['Users', 'Watching']
def otherRoles = remoteUserRoles - rolesToCheck
if(remoteUserRoles && !otherRoles) {
//user has some roles, but no roles when you subtract both Users and Watching
} else if(remoteUserRoles && otherRoles) {
//user has remoteUsersRoles, and some other roles, you can inspect otherRoles to see what remains once you've removed users and watching
} else {
//remoteUserRoles was empty to start with, subtracting has no effect
0 votes

I want to question the "watching" - do you genuinely have a project role of "watching" alongside the project roles like User, developer and administrator?  (Assuming you've not removed the default project roles)

If you do, then I'd write your query as

if ("Users" in remoteUsersRoles || "Watching" in remoteUsersRoles )

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events