Workflow to set the state In Progress to a parent task

Hi all,

I want to create a workflow that set a state o parent issue when on of yours subtask was set to In Progress.

I have see the default Workflow Subtasks (https://www.jetbrains.com/help/youtrack/server/workflow-subtasks.html) but in that Use Case we have:

  • Open parent task when subtask changes to an unresolved state (on-change)
  • Fix parent task when all subtasks are resolved (on-change)

Can you help me to create a JS code for my scope?

Thanks a lot

0
4 comments
Official comment

Marco Tarantino please find the code below:

const entities = require('@jetbrains/youtrack-scripting-api/entities');
const workflow = require('@jetbrains/youtrack-scripting-api/workflow');

exports.rule = entities.Issue.onChange({
  title: 'Set parent task to In Progress when subtask changes to In Progress',
  guard: (ctx) => {
    return ctx.issue.isReported && ctx.issue.becomes("State", "In Progress");
  },
  action: function (ctx) {
    const processParent = function (issue) {
      if (issue.links['subtask of'].isEmpty()) {
        return;
      }
      const parent = issue.links['subtask of'].first();
      if (parent && parent.project && !parent.project.isArchived && parent.isReported) {
        const field = parent.project.findFieldByName(ctx.State.name);
        if (field) {
          const value = field.findValueByName(ctx.State.InProgress.name);
          if (value) {
            parent.State = value;
            workflow.message('Automatically set parent {0} to In Progress', parent.id);
            return parent;
          }
        }
      }
    };

    let issue = ctx.issue;
    while (issue) {
      issue = processParent(issue);
    }
  },
  requirements: {
    State: {
      type: entities.State.fieldType,
      InProgress: {
        name: "In Progress"
      }
    }
  }
});

This will set the parent task to In Progress whenever a subtask is set to that state. You can use this code to create a separate rule within the default Subtasks workflow or add it as a separate workflow.

Hi! The Subtasks workflow will set the parent issue to Open if one of its subtasks is set to any state that isn't marked as “Resolved” (that includes the “In Progress” state). 

Based on your description of the task at hand, it should not require any adjustments, so you should be good to go if you attach this default workflow to your YouTrack project. Or do you have any additional requirements in mind?

0

Hi Stanislav Dubin, my goal is to automatically set the parent task state to “In progress” when at least one of its subtask is set to the same state.

With standard “Subtasks” workflow, I can only set the parent to ‘Open’ or ‘Fixed’, not ‘In progress’

0

Please sign in to leave a comment.