Assign issue to project role e.g. user group depending on custom field value (Select List (single choice))

Hi Script Runner Users,

I'm new to script runner and want to achieve thing which more of people are using (I think at least). Depending on value from custom field the issue should be assigned  to different user group.

if system=system1, than assign to system1_approval_group

if system=system2, than assign to system2_approval_group

I found post condition where assignment is to first user of project role. This would be also acceptable but I'm not able to extend this function depending on custom field.

Can someone help me, please?

Thanks a lot and nice regards!

4 answers

0 vote

You can't assign an issue to a group.  Only to individual users.

Hi Nic, yes, it should be first user of group or role. I can paste the code for assigning to 1st person in project role (but without most needed condition - depending on system)


Script Source

package com.onresolve.jira.groovy.canned.workflow.postfunctions


import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.MutableIssue


import com.atlassian.jira.util.ErrorCollection

import com.onresolve.jira.groovy.canned.CannedScript

import com.onresolve.jira.groovy.canned.utils.CannedScriptUtils

import org.apache.log4j.Logger


class AssignToRoleMember implements CannedScript {


    public static String FIELD_ROLE_ID = "FIELD_ROLE_ID"

    def log = Logger.getLogger(AssignToRoleMember.class)

    def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager.class)


    String getName() {

        "Assign to first member of role"



    String getDescription() {

        "Assign to the first member of the specified role"



    List getCategories() {




    List getParameters(Map<String, String> params) {



                Label: "Role",

                Name: FIELD_ROLE_ID,

               Type: "list",

                Values: CannedScriptUtils.getAllRoles(false),

                Description: "Specify the role the previous assignee must be in",





    ErrorCollection doValidate(Map<String, String> params, boolean forPreview) {




    Map doScript(Map<String, Object> params) {

        def projectRoleId = params[FIELD_ROLE_ID] as Long

        def role = projectRoleManager.getProjectRole(projectRoleId)

        assert role // role must be valid

        def issue = params["issue"] as MutableIssue

        def actors = projectRoleManager.getProjectRoleActors(role, issue.getProjectObject())

        def roleUsers = actors.getUsers()

        if (roleUsers) {



        else {

            log.warn ("Wanted to set the assignee to a member of the ${} role, but it had no members")




    String getDescription(Map<String, String> params, boolean forPreview) {

        def projectRoleId = params[FIELD_ROLE_ID] as Long

        def role = projectRoleManager.getProjectRole(projectRoleId)

        "Assign this issue to the first member of the <b>${}</b> role"


    Boolean isFinalParamsPage(Map<String, String> params) {




You need to insert your code into the "doscript" function

Hi Nic, and can you help me how the condition should look like? Thanks a lot!

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

561 views 1 18
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