Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move task from one parent to another and fix rollup hours on previous parent #348

Closed
jasondavidcamp opened this issue Jul 7, 2020 · 6 comments

Comments

@jasondavidcamp
Copy link

We tend to change the parent of a task from one PBI to another which makes our "Rollup Completed Work" rule only work for the new parent. Are there any helpful tips on solving this issue?

  if (self.HasParent() && self.Parent.TypeName != "Task")
  {
      var parent = self.Parent;
      parent["Microsoft.VSTS.Scheduling.CompletedWork"] = parent.Children.Sum(task => task.GetField<double>("Microsoft.VSTS.Scheduling.CompletedWork", 0d));
      logger.Log(LogLevel.Information, "Rollup completed work hours from child {0} #{1} to parent {2} #{3}", self.TypeName, self.Id, parent.TypeName, parent.Id);
  }
@jessehouwing
Copy link
Collaborator

Go back 1 revision, check the old parent, update where needed.

@jasondavidcamp
Copy link
Author

I like that idea. Thanks for the guidance.

@jasondavidcamp
Copy link
Author

It doesn't look like I can use the Parent property on the self.PreviousRevision

@jessehouwing
Copy link
Collaborator

jessehouwing commented Jul 7, 2020 via email

@jasondavidcamp
Copy link
Author

When I use WorkItemLinks on the PreviousRevision, it seems to always come back empty.
var linkcount = self.PreviousRevision.WorkItemLinks.Count();

Maybe I'm having the same issue as willstones did here

@jasondavidcamp
Copy link
Author

jasondavidcamp commented Jul 9, 2020

since links on PreviousRevsion don't work, I ended up creating 2 rules

<!-- subtract completed work hours when a child work item is removed -->
<rule name="RecalculateCompletedWorkForBereavedParent" appliesTo="Bug,Change Request,Epic,Feature,Requirement">
    <![CDATA[
    var currentCompletedWork = self.GetField<double>("Microsoft.VSTS.Scheduling.CompletedWork", 0d);
    var recomputedCompletedWork = self.Children.Sum(task => task.GetField<double>("Microsoft.VSTS.Scheduling.CompletedWork", 0d));
    if (System.Math.Round(currentCompletedWork,2) != System.Math.Round(recomputedCompletedWork,2))
    {
        self["Microsoft.VSTS.Scheduling.CompletedWork"] = recomputedCompletedWork;
        logger.Log(LogLevel.Warning, "{0} Fixed completed work hours on {1} #{2} from {3} hours to {4} hours", System.DateTime.Now, self.TypeName, self.Id, currentCompletedWork, recomputedCompletedWork);
    }
    ]]>
</rule>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants