Groovy Condition - User (assignee) NOT in group

Hi there.

I'm looking for a way to set the condition "assignee is not in group"

I ended up with something like this, but I don't know if that is the right wat to do it:

import com.atlassian.jira.component.ComponentAccessor

def groupManager = ComponentAccessor.getGroupManager()
!(groupManager.isUserInGroup(issue.assignee?.name, 'groupname'))

EDIT:

and working code for checking if assignee is not in any of groups:

import com.atlassian.jira.component.ComponentAccessor

def groupManager = ComponentAccessor.getGroupManager()

!(
(groupManager.isUserInGroup(issue.assignee?.name, 'groupnameA'))
||
(groupManager.isUserInGroup(issue.assignee?.name, 'groupnameB'))
)

7 answers

1 accepted

2 votes

It's hard to read that without adding the proper code formatting.

Your code looks ok. It could be written more idiomatically, but looks like it will work.

I might rewrite the last line like so:

! ['groupA', 'groupB'].any {groupManager.isUserInGroup(issue.assignee?.name, it)}

Thanks for the help. I added the code and it works like a charm :)

no worries... small suggestion above (untested).

Cool, looks far better and clean :)

Hi Blazej,

Haven't tried this but since it is groovy I am pretty sure you could do something like this.

def groupManager = ComponentAccessor.getGroupManager()
if(groupManager.getGroupNamesForUser(issue.assignee).contains("Administrator"))

Let me know if this worked for you.

Bhushan Nagaraj's Visual Thumbprint

But isn't this the code fo checking if user IS in group? I were looking for something exactly opposite :)

0 vote

Looks fine to me. Are you saying it doesn't work?

No no, I was just not sure if I placed "!" properly and afraid if it won't corrupt anything :)

Thanks for the opinion, I can now go and test it out :)

Damn, Script Runner condition won't allow me to group conditions. Can I use such structure to check if user is not in ANY fo the groups?:

import com.atlassian.jira.component.ComponentAccessor

def groupManager = ComponentAccessor.getGroupManager()

!((groupManager.isUserInGroup(issue.assignee?.name, 'groupnameA'))||(groupManager.isUserInGroup(issue.assignee?.name, 'groupnameB')))

Please, forgive me such noobish questions, I simply don't know groovy nor java, so I'm kinda like blindman trying to complete sudoku :)

I am new to use Groovy Scrip Runner. I want to implement 'User Not In Group' condition.

Please tell we how can I create custom condition that can be applyed on any workflow transition and that can work similer to the in built condition 'User Is In Group'

I am new to use Groovy Scrip Runner. I want to implement 'User Not In Group' condition.

Please tell we how can I create custom condition that can be applyed on any workflow transition and that can work similer to the in built condition 'User Is In Group'.

But not able to link it with workflow and not clear how to use these written script. Please help me.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,314 views 14 20
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot