Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
badges earned

Your Points Tracker
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Set Approver Based on the Requestor's Group

Hi Community. I'm new to groovy and I just want to seek help here. How can I set approver/s based on the requestor's group upon creation using post function scriptrunner

For example , Requestor 1 belongs to the Group 1 and Requestor 2 belongs to the Group 2 , if Requestor 1 creates a ticket, Approver must be the Approver 1 , and same rule applies to Requestor 2

any comments/suggestion is really appreciated. If you have sample code to work on, that would be great. Thank you!


2 answers

1 accepted

1 vote
Answer accepted

Hi Alvin, 

Assuming your approvers field is a multi user-picker type custom field and requestor is the user creating the issue, the code for a post function is as follows. Make sure to put in on your 'Create' transition.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager

ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
GroupManager groupManager = ComponentAccessor.getGroupManager()
UserManager userManager = ComponentAccessor.getUserManager()
CustomField approversField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("approversFieldName")
List<ApplicationUser> approversList = new ArrayList<>()

Map<String, String> approverMap = new HashMap<>()
approverMap.put("group1", "approver1")
approverMap.put("group2", "approver2")

Collection<String> groups = approverMap.keySet()
for(int i = 0; i < groups.size(); i++){
if(groupManager.isUserInGroup(currentUser, groups[i])){
issue.setCustomFieldValue(approversField, approversList)

Hi @Ivan Tovbin , Thank you for a quick turn-around , I already have a script but will definitely try this one. Thanks! I think you might help me with my another question about hashmap, multikeymaps. I have raised another question here in the community

I will definately take a look at your other question. In the meantime, please mark this solution as 'Accepted' if it resolved your issue.


Hi, my name is Jonathan, I manage an app called Power Scripts. I see you already have the answer you're looking for but I thought I might share this in case anyone ready this is not a hardcore groovy developer who does not know off the top of their head which classes to import and how to maintain those classes during upgrades. Plus, I think it is a lot easier to read and write. I created this script, like most I write, in less than 5 minutes without doing any research first.

For example, instead of writing this line that does not even fit in the window:

CustomField approversField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("approversFieldName")

I can just call the field like this:


Makes the script a lot easier when I can just call the fields by name. Anyway, here is the script:

struct grpApprv {
    string group;
    string approver;

grpApprv [] gas;

gas += {"group1", "Approver1"};
gas += {"group2", "Approver2"};

for(grpApprv ga in gas) {
    if(userInGroup(, currentUser())) {
        #{Approvers} += ga.approver;

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Marketplace Apps & Integrations

Staying organized with Jira: best practices for a better project management

Project managers know this problem: A “mountain of work” lays in front of you, and you don’t know how and where to tackle them. Different to-dos lie ahead, but just one task after the other can be ha...

224 views 2 1
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you