Override default assignee on issue creation

Hi

I want to accomplish the following requirement but constantly encounter problems=)

1) When an issue got created in a certain project and assignee is set as Default Assignee I need to change assignee to a specific user according to issue type (I have three issue types in that project and each one should go to its own default assignee)

First I've tried to run groovy script in a post action when issue is created in the workflow designed. This didn't work, Jira ignores this and uses proeject's default assignee. The order of post functions didn't matter

Then I tried to create a custom listner, attach to IssueCreated event and do the trick - but result is this the same.

I've found this article https://answers.atlassian.com/questions/191021/groovy-change-assignee-based-on-custom-field-valuebut I don't really like the idea of creating a scripting field.

Is there any, more elegant, way of doing this?

2 answers

1 accepted

I've finally made it

The trick was that I did everyting correctly in the very begining. Abovementioned bug with switch statement was a bad guy.

so

1) This won't work if you do it in the event listner

2) the only way was to add a script as workflow post function and set it to be executed before IssueCreated event

0 vote

I suspect the problem is that the decisions made by you selecting "default user" are being made before your code runs, so your listener and post-functions don't actually know the default was set. It might be useful to show us the exact code you have for them.

My other guess is that your user doesn't have "assign issues" - the functoins will respect the permissions and ignore your user unless they have the rights to assign issues.

Hi Nic

My other guess is that your user doesn't have "assign issues" -

Well all users have Assignable User permissions. I've already checked that, so this not the issue.

It might be useful to show us the exact code you have for them.

Sure, here is my code sample in form of lisnter

imports....


class InceptionDefaultAssignee extends AbstractIssueEventListener {

    Category log = Category.getInstance(InceptionDefaultAssignee.class)



    @Override
    void workflowEvent(IssueEvent event) {
        super.issueCreated(event)    //To change body of overridden methods use File | Settings | File Templates.
        ComponentManager componentManager = ComponentManager.getInstance()
        def permissionManager = componentManager.getPermissionManager()

        def user1 = componentManager.getUserUtil().getUser("user1")
        def user2 = componentManager.getUserUtil().getUser("user2")
        def user3 = componentManager.getUserUtil().getUser("user3")

        MutableIssue currentIssue = issue


        switch (currentIssue.issueTypeId)
        {
        //bug
            case 1 :
                if (permissionManager.hasPermission(Permissions.ASSIGNABLE_USER, issue, user1)) {
                    currentIssue.setAssignee(user1)
                }
                break
        //task
            case 3 :

                if (permissionManager.hasPermission(Permissions.ASSIGNABLE_USER, issue, user2)) {
                    currentIssue.setAssignee(user2)
                }
                break
        //question
            case 36 :

                if (permissionManager.hasPermission(Permissions.ASSIGNABLE_USER, issue, user3)) {
                    currentIssue.setAssignee(user3)
                }
                break
            default: break
        }
    }
}

Ah, no, it is "can assign" I meant, not "assignable". They user needs to be able to assign.

This is also not the root cause unfourtunately=( all users (including one that creates the issue) have both Can Assigne and Assignable User permissions

Ok, it's not that then.

In your code, are you sure the "getuser" calls are actually getting any users? The calls you're using are deprecated if I remember correctly, but I'm wondering if they return nulls (if they do, it would explain why the setAssignee does nothing)

In your code, are you sure the "getuser" calls are actually getting any users?

Yep, this works fine. I've added logging - user is populated correctly

However, I've found two bugs in my code

  1. In event lisnter you can't do MutableIssue currentIssue = issue, you should use MutableIssue currentIssue = event.issue instead
  2. second was very funny. event.issue.issueTypeId returns string, not integer so my switch statement did nothing at all

However even when I fixed all the bugs - result is still the same=(

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,293 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