Here is code for a post-function which sets a sub-task's priority to that of its parent. It should be set on the initial 'Create Issue' transition in a workflow assigned to 'Sub-task' issue types.
package com.atlassian.jira.workflow.function.issue; import com.opensymphony.module.propertyset.PropertySet; import com.opensymphony.workflow.FunctionProvider; import com.atlassian.jira.issue.IssueImpl; import com.atlassian.jira.config.ConstantsManager; import com.atlassian.jira.ManagerFactory; import org.apache.log4j.Category; import org.ofbiz.core.entity.GenericValue; import java.util.Map; /** * Sets the priority of a subtask to that of its parent issue. */ public class SubtaskInheritPriorityFunction implements FunctionProvider { private static final Category log = Category.getInstance(SubtaskInheritPriorityFunction.class); private ConstantsManager constantsManager; public void execute(Map transientVars, Map args, PropertySet ps) { ConstantsManager constantsManager = ManagerFactory.getConstantsManager(); MutableIssue issue = (MutableIssue) transientVars.get("issue"); Issue parent = issue.getParentObject(); issue.setPriority(parent.getPriority()); issue.store(); } }
The plugin definition XML is:
<workflow-function key="inheritpriority-function" name="Inherit Parent Priority" class="com.atlassian.jira.plugin.workflow.WorkflowNoInputPluginFactory"> <description>Sets the priority of a subtask to that of its parent issue.</description> <function-class>com.atlassian.jira.workflow.function.issue.SubtaskInheritPriorityFunction</function-class> <orderable>true</orderable> <unique>true</unique> <deletable>true</deletable> <weight>100</weight> <default>false</default> <resource type="velocity" name="view" location="templates/jira/workflow/com/atlassian/jira/plugin/assigntoreporter-function-view.vm"/> </workflow-function>
In JIRA 3.4 the code to update the field would be:
IssueImpl issue = (IssueImpl) transientVars.get("issue");
Issue parent = issue.getParentIssue();
issue.setPriority(parent.getPriority());
issue.store();

Comments (11)
Oct 19, 2006
Christoph Ertl says:
This one looks so easy, but it does not work for me. I'm usinig JIRA 3.6 and I'm...This one looks so easy, but it does not work for me.
I'm usinig JIRA 3.6 and I'm trying to write a post function, that sets the reporter and the assignee of a newly created sub-task to the ones of the main task.
I copied those lines above and tried to add the function to my sub-issue workflow transition "create", but I keep getting ClassCastExceptions.
Can anybody help me, please?
Oct 24, 2006
Nick Menere says:
Christoph, I have just updated the code to work with the latest version. Cheer...Christoph,
I have just updated the code to work with the latest version.
Cheers,
Nick
May 08, 2007
Matt Doar says:
I've attached a working version of this plugin, and it works with 3.8 ~MattI've attached a working version of this plugin, and it works with 3.8
~Matt
Jan 09, 2008
Matt Doar says:
Oops - looks like I used gunzip twice compress that attachment. I'll upload it a...Oops - looks like I used gunzip twice compress that attachment. I'll upload it again compressed just once.
May 23, 2007
Tim Corbitt says:
So could something similar be done for any field?? Meaning the sub-task would in...So could something similar be done for any field?? Meaning the sub-task would inherit certain fields from the parent??
Jul 09, 2007
Will Rau says:
I'm surprised there is not already a plugin that sets subtask values based on pa...I'm surprised there is not already a plugin that sets subtask values based on parent. does anyone know of one?
I'm especially keen for one that would update certain fields (component, fix release, priority) of subtasks when the parent is update.
Jul 10, 2007
Vincent Thoulé says:
Hi Will, I have implemented theses features as plugin in Kaamelot (3.7-1.10). P...Hi Will,
I have implemented theses features as plugin in Kaamelot (3.7-1.10).
Provided functions are :
all extending the abstract class : com.atlassian.jira.workflow.function.AInheritFromParentFunction
Modules declaration have been done as follow :
Jul 10, 2007
Will Rau says:
Interesting. I will see how well this plays in my Jira installation. ...Interesting. I will see how well this plays in my Jira installation. I had steered away from Kaamalot because it (please brace for pun impact) looked like it "came with a lot" of functionality that I didn't need.
sorry for the pun. couldn't resist.
Jan 18, 2008
Greg Sandell says:
inherit-jira-plugin.tar.gz has nothing in it...it's an empty tar file. Can...inherit-jira-plugin.tar.gz has nothing in it...it's an empty tar file. Can it be fixed? Thanks
Jan 22, 2008
Matt Doar says:
I think I fixed a few weeks ago. Make sure you use this attachment http://conflu...I think I fixed a few weeks ago. Make sure you use this attachment http://confluence.atlassian.com/download/attachments/134879/inherit-jira-plugin.tar.gz
not the earlier one which was oddly compressed twice. Let me know if the new one doesn't decompress properly.
Mar 05, 2008
Matt Doar says:
I've just tested the plugin with the jira 3.12 development kit and it worked fin...I've just tested the plugin with the jira 3.12 development kit and it worked fine. I've attached a new tar gzip file. Don't forget you have to add the function to the workflow used by your subtask issue type, and if subtasks aren't enabled, it didn't seem to be even loaded.