Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to assign an issue to the current user on create transition ?

Christophe May 17, 2012

I need to customize JIRA in order to assign automatically a Task issue to the current user.

The others types (Bug, Improvement, New feature) are not assigned (unassigned) by default.

To do so, I configured the project Default assignee to unassigned then I add the Assign to current user post function in the create transition of the Task issue associated workflow.

But it does seem to work (the newly created Task issues are not assigned).

Jira version is 4.4.1.

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

4 votes
Answer accepted
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 17, 2012

We use this little groovy script as a post-function on the create step, on certain projects. You could check the issue type there. Alternatively you could write a separate workflow for the task issuetype, and use the post-function "set field". This only sets it if the user left it as auto-assign or unassign.

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.security.Permissions

def componentManager = ComponentManager.getInstance()
def currentUser = componentManager.jiraAuthenticationContext?.user
def permissionManager = componentManager.getPermissionManager()

if (! issue.assigneeId) {
    if (permissionManager.hasPermission(Permissions.ASSIGNABLE_USER, issue, currentUser)) {
        issue.assigneeId = currentUser.name
    }
}

Christophe May 17, 2012

Your solution requires to develop a plug-in ?

Jens Helmstedt April 8, 2016

I tried that script out and it worked fine with all projects except one.

When I leave the issue on "auto-assign" it is set on "unassinged" afterwards.

I have no clue what the reason could be for that. The project has the same settings as the others (especially the same workflow wink ). It's just a newer project (Jan 2016) than most of the others (2014).

Any suggestion what I could try?

Far from that it's a great solution and exactly what I was looking for.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 10, 2016

Perhaps the current user doesn't have the ASSIGNABLE permission in that project?

Jens Helmstedt April 10, 2016

He has. He's the admin.

He can assign himself manually.

Jens Helmstedt April 13, 2016

Ok, meanwhile I found out it doesn't work at all.

I accidentally thought it would work because there was a built-in rule on the transition that set the assignee to the user of a specific role. I wasn't aware that I myself was set to that role.

But I tried it forth and back, also with issue.setAssignee(currentUser), also without all conditions. I haven't any idea anymore. sad

3 votes
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 17, 2012

Your apparoach should have worked I guess. See if it works after moving the post function to the last to be executed. Also that the workflow is published ;)

Edit: Should be first post function instead!

Christophe May 17, 2012

Thanks for the suggestion. I tried to move the assign post-function at the end of the list but it doesn't change anything.

The post function list is:

* Creates the issue originally.
* Re-index an issue to keep indexes in sync with the database.
* Fire a Issue Created event that can be processed by the listeners.
* Assign the issue to the current user. Please note that the issue will only be assigned to the current user if the current user has the 'Assignable User' permission.
I also checked that the workflow is published, active and associated to the type through a scheme ^^
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 17, 2012

Sorry to hear it dodn't work. You might have to do it in a listener! Try Jamie's script too. You can run it using the ScriptRunner plugin.

I am not possitive though because it is essentially the same code that is used in that post function.

Christophe May 20, 2012

Thanks for your response. I installed the ScriptRunner plugin developed by Jamie Echlin. I also use the sample script he suggested with some log traces to follow the execution in logs:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.security.Permissions
import org.apache.log4j.Logger

def log = Logger.getLogger("com.onresolve.jira.groovy.autoassign")
def componentManager = ComponentManager.getInstance()
def currentUser = componentManager.jiraAuthenticationContext?.user
def permissionManager = componentManager.getPermissionManager()

log.debug("Auto assign script for issue " + issue.key)
if (! issue.assigneeId) {
    if (permissionManager.hasPermission(Permissions.ASSIGNABLE_USER, issue, currentUser)) {
        log.debug("Assign to current user " + currentUser.name)
        issue.assigneeId = currentUser.name
    }
}

When I create an issue, the following trace appears in logs:

2012-05-21 14:49:35,351 ... [onresolve.jira.groovy.GroovyFunctionPlugin] In execute
2012-05-21 14:49:35,367 ... [onresolve.jira.groovy.GroovyRunner] Run called with args: (...)
2012-05-21 14:49:35,429 ... [onresolve.jira.groovy.autoassign] Auto assign script for issue SPR-377
2012-05-21 14:49:35,461 ... [onresolve.jira.groovy.autoassign] Assign to current user dev1
2012-05-21 14:49:35,461 ... [onresolve.jira.groovy.GroovyRunner] Time taken: 94

But the issue remains unassigned is GUI...

A screen capture is attached.

I tried to move the script execution in the post-function list (before and after the re-index of the issue), but the behavior is identical.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 20, 2012

Are you sure some other function is not changing it later? I use that code and it works fine. Put it as the first post-function.

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 20, 2012

I think the trick is in putting it as the first post function. If you do that, even the system "Update issue Field" post function will work. Just tested it now.

Christophe May 20, 2012

Here are all the functions called in the Create Issue transition:

Creates the issue originally.
— THEN
Script C:/Atlassian/Data/JIRA/scripts/auto_assign.groovy will be run.
— THEN
Re-index an issue to keep indexes in sync with the database.
— THEN
Fire a Issue Created event that can be processed by the listeners.
Christophe May 20, 2012

You're right ! And it works with the assign to current user post function.

I was cheated by the "Creates" and thought that I cannot assign if the issue wasn't created yet... Thank Jobin and Jamie for your time and your patience !

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 20, 2012

You need to put it even before 'Create the Issue Originally'. That's the trick!

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 20, 2012

Yes, put it first as I said! Create the issue originally will write it to the database. If you modify it afterwards you need to use a different method.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 20, 2012

No worries. But you've taken my code and given Jobin the points :-(

You can mark my answer as correct as well if it was helpful!

Christophe May 20, 2012

Finally I will use the embedded "Assign to Current Use". But I also discovered a nice plug-in to easilly add functionalities in JIRA

Thanks again.

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 20, 2012

:D I have up-voted you if that makes you feel any better!

And just to add on, you don't need the script runner plugin for this. I guess he used the system post function in the end. The trick was in using it before the issue got created. Credit to you to figure that out.

That was why I was confused initially. Because the script does the same thing what the system post fucntion does. The only difference is one is in groovy and the other in Java.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 21, 2012

Heh, thanks Jobin. Yes you are right about the script in the end not doing any more than the plugin, but when the requirement changes to "only set it to the reporter when the reporter is in the customer group", it would be easy to incorporate!

Kimberly Kohler April 30, 2015

If I make "Assign the issue to the current user..." the very first post function (before "Creates the issue originally"), my issue is assigned to the current user even if the user entered another assignee. If I make it the second post function, then it appears to only change the value if it was left as "Automatic" which is what I want. Unfortunately, this is having some other inconsistencies, which I am trying to fix.

0 votes
AKASHB May 22, 2013

Also can any body list down the steps to deploy a groovy script in jira.

0 votes
AKASHB May 22, 2013

Can any body help out in groovy script for jira, I am new to groovy and jira but have an intermediate knowledge of JIRA and java. So is there any documentation where i would find tutorials or any stuff? Also when writing an groovy scripts which all points shoould i remember like API and other stuff.

Thanks,

Hieu Le Trung November 11, 2013

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events