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.
Community moderators have prevented the ability to post new answers.
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 } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 ). 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Perhaps the current user doesn't have the ASSIGNABLE permission in that project?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here are all the functions called in the Create Issue transition:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You need to put it even before 'Create the Issue Originally'. That's the trick!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
: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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can find the documentation here https://jamieechlin.atlassian.net/wiki/display/GRV/Script+Runner
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.