|
|
|
Hi Anton.
I believe you misread my code then. The task itself is a subtask. I am retrieving its parent task then setting the subtask based on values from the parent. Note the following fragment: {code title=Code Fragment|borderStyle=solid}if (task.isSubTask()) { ComponentManager componentManager = ComponentManager.getInstance(); IssueManager issueManager = componentManager.getIssueManager(); MutableIssue parent = issueManager.getIssueObject(task.getParentId()); task.setComponents(parent.getComponents()); task.setFixVersions(parent.getFixVersions()); task.store(); }It only completes this set of code if the task that initialized the post-function is a subtask. It then retrieves the parent task and sets the subtask based on the parent. Following your instructions, this should work correctly. (ignore the last comment)
Hi Anton. I believe you misread my code then. The task itself is a subtask. I am retrieving its parent task then setting the subtask based on values from the parent. Note the following fragment: Code Fragment if (task.isSubTask())
{
ComponentManager componentManager = ComponentManager.getInstance();
IssueManager issueManager = componentManager.getIssueManager();
MutableIssue parent = issueManager.getIssueObject(task.getParentId());
task.setComponents(parent.getComponents());
task.setFixVersions(parent.getFixVersions());
task.store();
}
It only completes this set of code if the task that initialized the post-function is a subtask. It then retrieves the parent task and sets the subtask based on the parent. Following your instructions, this should work correctly. Note: This is a post-create function. When a subtask is created, this plug-in code is run. It could have something to do with this. Here is the workflow XML: <workflow> <meta name="jira.description">Open/Close/Re-Open transitions for subtasks.</meta> <initial-actions> <action id="1" name="Create"> <results> <unconditional-result old-status="null" status="open" step="1"> <post-functions> <function type="class"> <arg name="class.name">com.atlassian.jira.workflow.function.issue.IssueCreateFunction</arg> </function> <function type="class"> <arg name="class.name">ca.mda.jira.plugin.workflow.functions.SetComponentAndVersion</arg> </function> <function type="class"> <arg name="class.name">com.atlassian.jira.workflow.function.issue.IssueReindexFunction</arg> </function> <function type="class"> <arg name="eventTypeId">10005</arg> <arg name="class.name">com.atlassian.jira.workflow.function.event.FireIssueEventFunction</arg> </function> </post-functions> </unconditional-result> </results> </action> </initial-actions> ... </workflow> I have reproduced the problem with the exact scenario you listed. See the following code.
IssueUpdate.java public class IssueUpdate implements FunctionProvider { public void execute (Map transientVars, Map args, PropertySet ps) throws WorkflowException { MutableIssue issue = (MutableIssue)transientVars.get("issue"); if (!issue.isSubTask()) { Collection subtasks = issue.getSubTaskObjects(); for (Iterator it = subtasks.iterator(); it.hasNext(); ) { // update then store to the DB MutableIssue subtask = (MutableIssue)it.next(); // this call works subtask.setAssignee(issue.getAssignee()); // these two calls do not seem to work subtask.setFixVersions(issue.getFixVersions()); subtask.setComponents(issue.getComponents()); // store the issue subtask.store(); } } } } The result of this is that the assignee is set properly, but the fix version(s) and components are not. Alastair,
Please accept my apologies for missing the point. You are right, calling save() on the issue will not do the trick. You need to call: Map actionParams = EasyMap.build("issue", issue.getGenericValue(), "issueObject", issue, "remoteUser", ManagerFactory.getWorkflowManager().getRemoteUser(transientVars), "dispatchEvent", Boolean.FALSE); ActionResult aResult = CoreFactory.getActionDispatcher().execute(ActionNames.ISSUE_UPDATE, actionParams); Note that the "dispatchEvent" parameter is set to false to ensure that the Issue Updated event is not fired. Unfortunately, I did not get a chance to test that the above code works. If you run into trouble, please post a question to the JIRA Dev forum: Also, the following document might be helpful: I believe that a re-index is require to force the fix version(s) and component(s) through properly. This is the fix for this problem and thus this issue may be resolved IMO (as the reporter).
I had an almost identical plugin I created for a post function and had the same issues. My eventual fix was to remove the .store() line and place my post function at the very top of the tree BEFORE create issue. That worked perfectly and also solved the problem of the modifications being logged as changes in the Change History. (Which I did not want)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
At the moment, setting fields on the parent issue does not affect its sub-tasks. Please vote for JRA-5225 for this feature.
In code, you will need to do the work yourself by looping over the children and setting the fields as needed.
If you have any coding questions, please post the questions to the JIRA Dev forum:
http://forums.atlassian.com/forum.jspa?forumID=100
I will resolve the issue for now, but if I misunderstood what you are after, please let us know.
Thanks,
Anton