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 votes

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.security.roles.ProjectRoleManager

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() {

        ["Function"]

    }

 

    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) {

        null

    }

 

    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) {

            issue.setAssignee(roleUsers.toList().first())

        }

        else {

            log.warn ("Wanted to set the assignee to a member of the ${role.name} 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>${role.name}</b> role"

    }

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

        true

    }

}

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 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 ...

2,859 views 12 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
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