Creating subtask on transition only if subtask assignee has a specific role

Germain Vincent September 5, 2017

Hello,

 

I'm working on an environment where it is possible for an administrator to create a JIRA ticket and as many subtasks as needed.

It's something quite easy to deploy with post script function.

When the subtask is created, during the transition, administrator will choose a subtask assignee for the subtask.

 

I would like to set up a condition that will allow the administrator to allocate subtask to subtask assignee only if they are in a specific group of users.

In my case subtask assignee must be part of 'Administrators' or 'Developers'.

In the case subtask assignee is not part of this two group I would like the subtask not to be created.

 

Do you have any idea on which condition I could set up?

 

Thanks in advance.

 

Regards,

 

2 answers

1 accepted

1 vote
Answer accepted
Gaston Valente
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 5, 2017

Germain, 

Are you using roles or groups?

If your using standard jira, Administrators and Developers are roles, but maybe you created two groups with that names.

Germain Vincent September 5, 2017

Hi Gaston,

 

Thanks for your quick answer.

I'm not sure cause I wasn't in the company when roles or maybe groups were created. Of course, administrator who did it is not available those days.

Where can I see if groups are created?

At the moment I only know the way to manage "roles" by going on "Users and roles" tab.

Germain Vincent September 5, 2017

It seems that there is no group in my context. Only roles.

Germain Vincent September 5, 2017

Hi Patrick,

 

Thanks but the link is not working.

Thomas Schlegel
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 5, 2017

@Germain Vincent - it was spam - I have removed it

Gaston Valente
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 5, 2017

Hi Germain,

So, you need to use roles instead of groups in that condition, is that correct?

Germain Vincent September 6, 2017

Ok Thomas, thank you.

Hey Gaston, yes that's correct, I'm looking for a solution with roles 'administrators' and 'developers'.

Thanks.

Germain Vincent September 6, 2017

It seems that's the solution with groups is easy to deploy. I will ask my management if they should allow me to create groups.

In this case I may not require more help.

Keep you up to date.

 

Regards,

 

Germain.

Germain Vincent September 6, 2017

It's ok, I will create groups.

 

Thanks.

0 votes
Germain Vincent September 5, 2017

At the moment I tried this script but even when the subtask assignee is not in one of the two roles the subtask is created anyway...

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.ComponentManager

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_12500")
ApplicationUser user = issue.getCustomFieldValue(cField) as ApplicationUser

def groupManager = ComponentAccessor.getGroupManager()
groupManager.isUserInGroup(user, 'Administrators') || groupManager.isUserInGroup(user, 'Developers')
Gaston Valente
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 6, 2017

Maybe the guys from Adaptavist have a better answer, but i think you can directly use this on the conditions field:

isUserMemberOfRole("Administrators") || isUserMemberOfRole("Developers")

 Let me know if it's working

Germain Vincent September 7, 2017

Hi Gaston,

 

This solution is perfectly working!

I will use it in some cases.

 

Thanks a lot!

Gaston Valente
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 9, 2017

Great!

Suggest an answer

Log in or Sign up to answer