Override default assignee on issue creation

Dnevnik_ru April 20, 2014

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

1 vote
Answer accepted
Dnevnik_ru April 21, 2014

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 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 21, 2014

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.

Dnevnik_ru April 21, 2014

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

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 21, 2014
Ah, no, it is "can assign" I meant, not "assignable". They user needs to be able to assign.
Dnevnik_ru April 21, 2014

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

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 21, 2014

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)

Dnevnik_ru April 21, 2014

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 Sign up to answer