Redmine: change parent task field when modifying subtask field

Redmine custom workflow for parent task

In Redmine tasks and subtasks have a close relationship. For instance we can avoid a parent task to be closed if a subtask is still open. But we can make this relationship even more dependent by means of the Custom workflows plugin.

With this plugin we can significantly extend the behaviour of Redmine to better adapt it to our processes.

How to change a parent task field when editing a subtask field

Let's say we've got a tracker called “Feature” with id=2. In this tracker there is a list field (id= 2) called “Tested”, with values “Yes” and “No”.

There is another tracker called “Test” with id=4. This tracker includes a field called “Test passed?” (id= 3) with values “OK”, “KO” and void.

We want that the field “Tested” in parent task automatically changes to value “Yes” when in the subtask the value of the field “Test passed?” changes to OK.

These are the steps you should follow:

  1. Install Custom Workflows plugin:
    If not yet, please install the plugin (standard procedure). We've tested the plugin in last Redmine versions (4.2 and 5.0) and it works perfectly.
  2. Create a new custom workflow Go to Administration > Custom workflows and create a new workflow with the following code:

    Name: give a descriptive name to the custom workflow
    Observable object: Issue
    Active: check
    Saving observable objects > Workflow script exectuable after saving observable object:
if !parent.nil? && custom_field_value(3).to_s == "OK"
   self.parent.custom_field_values = { 2 => "Yes"}
   self.parent.save_custom_field_values
end

3. Save the new workflow. And that's it! Now, when a subtask containing the field Test passed? is checked to OK, its parent task will automatically change its field value “Tested” to “Yes”.

Want to add more conditions to this workflow?

OK, you like this automatism but you need it only to work under certain circumstances. For instance you want the workflow to apply only when the subtask is set to a certain status and only for a certain tracker. Then the code would be the following:

Saving observable objects > Workflow script exectuable before saving observable object:

if @issue.status_id_changed? && @issue.status_id == 3 && tracker_id == 4
@checkfield = subject.present? ? (status_id_changed?) : false
end

Saving observable objects > Workflow script exectuable after saving observable object:

if @checkfield && !parent.nil? && custom_field_value(3).to_s == "OK"
   self.parent.custom_field_values = { 2 => "Yes"}
   self.parent.save_custom_field_values
end
TIP: Do you like the Redmine theme in the image? It is the fancy Zenmine by Best Redmine Theme.

About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *