Inheriting subtask priority from parent

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();

Labels

workflow workflow Delete
plugin plugin Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. 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?

  2. 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

  3. May 08, 2007

    Matt Doar says:

    I've attached a working version of this plugin, and it works with 3.8 ~Matt

    I've attached a working version of this plugin, and it works with 3.8

    ~Matt

    1. 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.

  4. 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??

  5. 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.

    1. 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 :

      • com.atlassian.jira.workflow.function.InheritPriorityFunction
      • com.atlassian.jira.workflow.function.InheritComponentsFunction
      • com.atlassian.jira.workflow.function.InheritFixVersionsFunction
        all extending the abstract class : com.atlassian.jira.workflow.function.AInheritFromParentFunction

      Modules declaration have been done as follow :

      <workflow-function key="inheritpriority-function" name="Inherit Parent Priority" i18n-name-key="admin.workflow.function.inherit.parent.priority.display.name"
      	class="com.atlassian.jira.plugin.workflow.WorkflowNoInputPluginFactory">
      	<description key="admin.workflow.function.inherit.parent.priority.description" >Sets the priority of a subtask to that of its parent issue.</description>
      		<function-class>com.atlassian.jira.workflow.function.InheritPriorityFunction</function-class>
      	<orderable>true</orderable>
      	<unique>true</unique>
      	<deletable>true</deletable>
      	<weight>100</weight>
      	<default>false</default>
      	<resource type="velocity" name="view" >$i18n.getText("admin.workflow.function.inherit.parent.priority.description", "<b>", "</b>")</resource>
      	<resource type="i18n" name="i18n" location="com.atlassian.jira.workflow.functions" />
      </workflow-function>
      <workflow-function key="inheritcomponents-function" name="Inherit Parent Components" i18n-name-key="admin.workflow.function.inherit.parent.components.display.name"
      	class="com.atlassian.jira.plugin.workflow.WorkflowNoInputPluginFactory">
      	<description key="admin.workflow.function.inherit.parent.components.description" >Sets the components of a subtask to that of its parent issue.</description>
      <function-class>com.atlassian.jira.workflow.function.InheritComponentsFunction</function-class>
      	<orderable>true</orderable>
      	<unique>true</unique>
      	<deletable>true</deletable>
      	<weight>100</weight>
      	<default>false</default>
      	<resource type="velocity" name="view" >$i18n.getText("admin.workflow.function.inherit.parent.components.description", "<b>", "</b>")</resource>
      	<resource type="i18n" name="i18n" location="com.atlassian.jira.workflow.functions" />
      </workflow-function>
      
      <workflow-function key="inheritfixversions-function" name="Inherit Parent Fix Versions" i18n-name-key="admin.workflow.function.inherit.parent.fixversions.display.name"
      	class="com.atlassian.jira.plugin.workflow.WorkflowNoInputPluginFactory">
      	<description key="admin.workflow.function.inherit.parent.priority.description" >Sets the Fix Versions of a subtask to that of its parent issue.</description>
      	<function-class>com.atlassian.jira.workflow.function.InheritFixVersionsFunction</function-class>
      	<orderable>true</orderable>
      	<unique>true</unique>
      	<deletable>true</deletable>
      	<weight>100</weight>
      	<default>false</default>
      	<resource type="velocity" name="view" >$i18n.getText("admin.workflow.function.inherit.parent.fixversions.description", "<b>", "</b>")</resource>
      	<resource type="i18n" name="i18n" location="com.atlassian.jira.workflow.functions" />
      </workflow-function>
  6. 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.

  7. 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

    1. 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.

  8. 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.