-
Hello. I'd like to make sure I'm doing things the right way. I have multiple events that can trigger different behavior on my user stories. Currently, I have implemented each behavior in different rules that are triggered by user story update. I guess if multiple behaviors/rules cause multiple saves at the same time, there will be issues right? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Great question. EventsLet's start from the event that triggers a rule. string magic = " - APPENDED";
if (selfChanges.Fields.ContainsKey("System.Title")) {
// check it is not recursion
var titleUpdate = selfChanges.Fields["System.Title"];
if (!titleUpdate.NewValue.Contains(magic)) {
self.Title = titleUpdate.NewValue + magic;
}
} The example (maybe a bit contrieved, but it's late here) checks that the change to the Title field was not made by the rule itself, to avoid infinite recursion. Infinite loopsIf you have more than one rule triggerd by Here is what you must not do. Rule A self.Tags = self.Tags + " my-tag-A"; Rule B string[] validTypes = new string[] { "Bug", "Epic", "Feature", "Product backlog item" };
if (validTypes.Contains(self.WorkItemType)) {
self.Field["Microsoft.VSTS.Common.AcceptanceCriteria"] += "<p>My standard criteria</p>";
} Rule A and B will trigger each other in an infinite loop. PerformanceClearly independent rules are simpler to write but have a negative effect on performance. The more rules, the slower a work item will converge to a stable state. Hope this help, and do not hesitate to ask additional questions. |
Beta Was this translation helpful? Give feedback.
Great question.
You must be careful to avoid cycles and loops: this version has no check for an infinite loop (it was possible with TfsAggregator because rules share the process memory).
Events
Let's start from the event that triggers a rule.
The
workitem.created
has no dependency on other rules but Azure DevOps may send it after aworkitem.updated
event!The
workitem.updated
event has an additionalselfChanges
parameter and you should use to write a guard.