Hey,
i need a workflow post-function which creates a subtask for each user of a jira-group (given by a usergroup-customfield) and assign it to him/her. does anybody have a solution for this problem?
i was thinking about the groovyrunner-plugin, but obviously you need to create an own groovy-script for this purpose, which i am not capable of... :-/
thank you very much in advance!
cheers,
michael
Can't think of anything which you would not need to code. Here's a script that should work:
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.Issue import com.opensymphony.user.Group import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.config.SubTaskManager import org.ofbiz.core.entity.GenericValue ComponentManager componentManager = ComponentManager.getInstance() CustomFieldManager customFieldManager = componentManager.getCustomFieldManager() def issueFactory = componentManager.getIssueFactory() def issueManager = componentManager.getIssueManager() def indexManager = componentManager.getIndexManager() def groupCf = customFieldManager.getCustomFieldObjectByName("GroupPicker") // name of group CF Group group = issue.getCustomFieldValue(groupCf) as Group if (group) { group.getUsers().each {String user -> MutableIssue newIssue = issueFactory.getIssue() newIssue.summary = "Sub-task for $user" newIssue.issueTypeId = '5' newIssue.project = issue.project newIssue.affectedVersions = issue.affectedVersions newIssue.fixVersions = issue.fixVersions Map<String,Object> newIssueParams = ["issue":newIssue] as Map<String,Object> def currentUser = componentManager.getJiraAuthenticationContext().getUser() GenericValue newIssueGv = issueManager.createIssue(currentUser, newIssueParams) indexManager.reIndex(newIssueGv); SubTaskManager subTaskManager = componentManager.getSubTaskManager() subTaskManager.createSubTaskIssueLink(issue, newIssue, componentManager.getJiraAuthenticationContext().getUser()) } }
Thank you very much, Jamie!
Just one more question: To implement this code I have to create a groovy-script-file on the server and then refer to it in the post-function "script component", right? Is it sufficient to put just this code into the file or do i have to use a any class-construct like it is the case for the other groovy file examples?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, no it's sufficent to just paste into a file exactly as is.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello, you script don`t work in JIRA 5.0.7. Help me, please.
Error:
javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script30.groovy: 4: unable to resolve class com.opensymphony.user.Group @ line 4, column 1. import com.opensymphony.user.Group ^ 1 error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear @Jamie Echlin [Adaptavist] , how to do the same with checkbox custom field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie,
just one more question: Why doesn't the subtask appear in the "assign to me" gadget?
How can I assure that?
Thanks again!
Cheers,
Michael
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I seem to have missed a critical line from the script I wrote for you:
newIssue.assigneeId = user
Put that line along with the other setters...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie,
thanks for your fast respone. Unfortunately this doesnt work. Maybe it is because if have modified your script simply. it does look like this now:
do i miss something here?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you put the whole script on gist.github.com? I can't see your script...
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This stuff with UserList you've added seems bogus.. what's the point of it? You can't have duplicate usernames in a group. Also use userList for a variable name.
You only need one of
newIssue.assignee = UserUtils.getUser(user)
newIssue.assigneeId = user
Are the subtasks created? Any errors in the log? Do all the users you're trying to assign have ASSIGNABLE permission?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
meanwhile the requirements have changed. our users wanted to have a list of checkboxes instead of the group-list customfield. thus i have created a checkbox-list with the names of the groups as options. since a user can be in multiple of these groups i used the userlist to avoid creating multiple subtasks for one user.
previously i used only the assigne-line. after i've recognized that the issue doesnt appear in the "assigned to me"-gadget i also added the assigneId-line like you have suggested it.
all subtasks will be created. there are no errors in the log. and yes, the users do have the assignable permission. after making some modifications on a subtask, it also appears in the "assigned to me"-gadget.
i was thinking that it is an indexing-problem and therefore added some reIndex-lines which unfortunately didnt work out... :-(
do you have any other ideas?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sounds like an indexing problem yes. So if you ran the post-function, the do a Admin -> Reindex, everything works properly?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try replacing with this section. Also I don't see any point in reindexing the parent issue.
boolean wasIndexing = ImportUtils.isIndexIssues(); ImportUtils.setIndexIssues(true); indexManager.reIndex(newIssueGv); SubTaskManager subTaskManager = componentManager.getSubTaskManager() subTaskManager.createSubTaskIssueLink(issue, newIssue, componentManager.getJiraAuthenticationContext().getUser()) indexManager.reIndex(newIssueGv); indexManager.reIndex(issue); ImportUtils.setIndexIssues(wasIndexing);
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.
No worries. How about an upvote or two for the comment and answer... ;-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
SO does this this look like a correct transition using the above script?
Add a new post function to the unconditional result of the transition.
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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.