Condition Based on Source Item field



I adjusted the code using one of the examples in the discussions section.

I would like to be able to perform the aggregation process from one item to another based on a condition that targets the source, and not target item.
For example, if this is the structure and I want to sum work hrs for Development tasks only while ignoring Testing:
---Story (Parent)
--------Task (Child)

When "total work hrs" field is changed on Task --> check if field "Discipline does not equal "Test" (on task work item)

Currently the condition is only allowed on the parent.

What can be done?

Closed Feb 14, 2015 at 3:06 PM by giuliov
Moved to GitHub Issue #4


molodec5 wrote Mar 17, 2014 at 7:54 AM

New code bolded:

file Condition.cs:
public string RightFieldName { get; set; }
public string WorkItemSide { get; set; }

file TFSAggregatorSettings.cs:
condition.RightFieldName = xmlCondition.LoadAttribute<string>("rightField", null);
condition.WorkItemSide = xmlCondition.LoadAttribute<string>("workItemSide", "target");

file MiscHelpers.cs:
modify AreAllConditionsMet function like this:
public static bool AreAllConditionsMet(this List<Condition> conditions, WorkItem targetWorkItem, WorkItem eventWorkItem)
    bool areAllTrue = true;
    WorkItem workItem = targetWorkItem;
    foreach (Condition condition in conditions)
        if (condition.WorkItemSide == "event") workItem = eventWorkItem;

        if (!condition.Compare(workItem))
            areAllTrue = false;
    return areAllTrue;
file WorkItemChangedEventHandler.cs:
replace all calls of function "AreAllConditionsMet(targetWorkItem)" to AreAllConditionsMet(targetWorkItem, eventWorkItem)

Now you can mark conditions what work item side you want to check:
(target side is default)
<Condition leftField="State" operator="NotEqualTo" rightValue="Removed" />
<Condition leftField="State" operator="NotEqualTo" rightValue="Removed" workItemSide="event"/>

Danoman5 wrote Mar 17, 2014 at 8:42 AM

Thanks for the quick response!

Unfortunately I will only be able to check this on Thursday.
Will update with the results.

Danoman5 wrote Mar 20, 2014 at 10:22 AM


Did you test this on your side?
I successfully created the build but the aggregations stopped working completely.
I tried using my old XML file that does not contain any conditions and it also failed.
(I am using TFS 2010 Server)


molodec5 wrote Mar 20, 2014 at 11:35 AM

I've been using this code now.
But it's not possible to answer without debugging why your code not works as you expect.

To debug your application:
  1. Go to TFS server and open Aggregator project in Visual Studio.
  2. Build project in debug mode and place result files (TFSAggregator.dll, TFSAggregator.pdb) to TFS's plugin directory.
  3. Make at least one breakpoint.
    For ex. at the start of magic - WorkItemChangedEventHandler.cs file:
                // Change this object to be a type we can easily get into
                WorkItemChangedEvent ev = notificationEventArgs as WorkItemChangedEvent;
  4. In VS choose menu: DEBUG->Attach to Process...
  5. Chose right process named "w3wp.exe" (you will need a bit of luck :) )
  6. Then make change to work item to trigger any aggregation and VS will stop the application at your breakpoint.
  7. PROFIT :)

wrote Feb 14, 2015 at 3:06 PM

honglin168 wrote May 22, 2015 at 8:43 PM

The change will not work for the requirement to sum work hrs for Development tasks only while ignoring Testing:
---Story (Parent)
--------Task (Child)

The change above will trigger the sum operation when the Task modified is not in State "Removed". However, the sum operation will still add all the hours from all child tasks, even if some of the child Tasks are "Removed".

Conditions only sets when to run the aggregation, but will not exclude items from aggregation.