Sum Story Points for parent Task

Hello! Somebody, please, help me with workflow! I need to summarize the Story Points fields from subtasks to parent task. I tried old workflows from the forum, but they don't work.
Please, begging you to share your workflows! Thank you!

1 comment
Comment actions Permalink

Hi!

We have already discussed this question in the support request, but I'll copy the workflow here in case anybody needs it:

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

exports.rule = entities.Issue.onChange({
  // TODO: give the rule a human-readable title
  title: 'Storypoints',
  guard: (ctx) => {
    return ctx.issue.fields.isChanged(ctx.StoryPoints);
  },
  action: (ctx) => {
        let issue = ctx.issue;
    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 && !parent.isResolved) {
        let sp = 0;
        parent.links['parent for'].forEach(function(child){
          sp += child.fields[ctx.StoryPoints.name];
        });
        parent.fields['Story points'] = sp;
        }
      };    
    while (issue) {
      issue = processParent(issue);}
  },
  requirements: {
    StoryPoints: {
      name: 'Story points',
      type: entities.Field.integerType
    },
    SubtaskOf: {
      type: entities.IssueLinkPrototype,
      name: 'Subtask',
      outward: 'parent for',
      inward: 'subtask of'
    }
  }
});
0

Please sign in to leave a comment.