Welcome to EMC Consulting Blogs Sign in | Join | Help

Crispin Parker's Blog

About Scrum for Team System and .Net development

Scrum for Team System v3 – Deep inside the Transition Event Service

This post relates to the Team Foundation Server Scrum for Team System process template event service. It assumes that you have a basic understanding of TFS work items and their fields.

In my last post I gave you an overview of the SfTS event service. Here I pick up the story again and look at the Transition service rules.

The event service code is written with extensibility in mind using the Microsoft Extensibility Framework. Out of the box it comes with two flavours of work item changed event processors; Transition and Aggregation. Both services have a set of rules that are defined in XML configuration files. The MEF plug-in assemblies and the controlling rules files can be found under the SfTS v3 installed web service folder on the TFS AT.

  • Default Installation Plug-in Folder:

    C:\Program Files\Scrum for Team System\Services\3.0\Plugins

  • Default Installation Rules Folder:

    C:\Program Files\Scrum for Team System\Services\3.0\Rules

The Transition Service

The transition service handles work item field changes from one value to another. Transition rules can be set to either update the source work item or work items linked to the source item.

Example Transition Rule

Scenario: In our SfTS project, we have a “Product Backlog Item” which links to several “Sprint Backlog Tasks” using the “Scrum.ImplementedBy” link type. When all the linked SBTs are set to a state of “Deleted” we want the Transition Service to automatically set the PBI to “Deleted”.

Here is sample of a XML transition rule that will apply our desired functionality:

<TransitionRule>
  <WorkItemTypeName
      source="Sprint Backlog Task"
      target="Product Backlog Item" />
  <Transition
      field="System.State"
      from="*"
      to="Deleted" />
  <LinkType target="LinkedItem">Scrum.ImplementedBy</LinkType>
  <ChangeNote>All tasks have been deleted</ChangeNote>
  <EligibleTargetStates>
    <State>In Progress</State>
    <State>Done</State>
  </EligibleTargetStates>
  <Replacements>
    <Replacement
        targetfield="System.State"
        type="Specified"
        decimalplaces="0"
        >Deleted</Replacement>
  </Replacements>
  <SiblingConditions>
    <SiblingCondition
        comparison="All"
        field="System.State"
        value="Deleted"
        siblingtype="Sprint Backlog Task"
        link="Scrum.ImplementedBy">
      <ExcludedStates>
        <State>Ignored</State>
      </ExcludedStates>
    </SiblingCondition>
  </SiblingConditions>
</TransitionRule>

Note: This isn’t a real rule that exists in the SfTS solution, its just an example.

Transition Rule Components Breakdown

So let’s break down the example rule to see what all the bits do.

  • Transition rule:

    <TransitionRule>

    • The container for the rule specification.

  • Work Item Type Name:
    <WorkItemTypeName source="Sprint Backlog Task" target="Product Backlog Item" />

    • Source. The type of the changed work item to match. The sample rule will match a source work item of type “Sprint Backlog Task”.
    • Target. The type of linked work item to update. the sample will target work items of type “Product Backlog Item”.

  • Transition:
    <Transition field="System.State" from="*" to="Deleted" />

    • Field. The name of the source work item field to monitor for changes.
    • From. The previous field value. The sample rule uses the wildcard “*” character, this means that any previous value will match the rule.
    • To. The new field value. The “to” value of the sample transition is set to “Deleted”. This means that this rule will only match work items that have a new “System.State” value of “Deleted”.

  • Link Type:

    <LinkType target="LinkedItem">Scrum.ImplementedBy</LinkType>

    • Target. The work item to target. This value can be either “Self” or “LinkedItem”.
    • The work item linkage type name. This is the type of linkage between the source and target work items.

  • Change Note:

    <ChangeNote>All tasks have been deleted</ChangeNote>

    • The note to be written to any updated work items change history.

  • Eligible Target States:
    <EligibleTargetStates> 
      <State>In Progress</State> 
      <State>Done</State> 
    </EligibleTargetStates>


    • A list of target work item states that are eligible to match this rule. This example will only target work items that are in a state of either “In Progress” or “Done”.

  • Replacements Collection:

    <Replacements>

    • This contains a collection of replacement specifications. A single rule can contain multiple replacements and update multiple fields on the target work item.

  • Replacement:
    <Replacement targetfield="System.State" type="Specified" decimalplaces="0">Deleted</Replacement>

    • Target Field. The field on the target work item to update.
    • Type. The replacement value specification type. This can be either “Specified” or “Expression”.
    • Decimal places. Used when specifying an expression to limit the precision of the returned value.
    • Node content. The replacement value. If the type is “Specified” then the value is used as is. A type of “Expression” means that the value represents a calculation expression. More on expressions below.

  • Sibling Conditions:

    <SiblingConditions>

    • A collection of Sibling condition specifications. More on siblings below.

  • Sibling Condition:
    <SiblingCondition comparison="All" field="System.State" value="Deleted" siblingtype="Sprint Backlog Task" link="Scrum.ImplementedBy">
      <ExcludedStates>
        <State>Ignored</State>
      </ExcludedStates> 
    </SiblingCondition>


    • Comparison. Specifies which sibling items to consider. This can be either “All” or “Any”.
    • Field. The field on the sibling item to compare. The sample rules specifies that the “System.State” field value should be examined.
    • Value. The field value to be matched. The sample rule checks for a value of "Deleted".
    • Sibling Type. The sibling work item type of the. Example: "Sprint Backlog Task".
    • Link. The work item linkage between the target and sibling work items. Example: "Scrum.ImplementedBy"
    • Excluded states. A list of sibling work item states to ignore from the condition test. 

Replacement expressions

The replacement component of the transition rule can specify two types of replacement value; Specified or Expression. “Specified” indicates that the value is used “as is” and “Expression” means that the value is interpreted as an expression.

Expressions allow you to specify a field name or a simple mathematical formula. Formulas can use the add, subtract, multiple and divide operator symbols (+, –, *, /) and the operand values can be either numerical or work item field names.

Expression Examples:

  • Scrum.BusinessValue / Microsoft.VSTS.Scheduling.StoryPoints

    This expression divides the “Scrum.BusinessValue” field value by the “Microsoft.VSTS.Scheduling.StoryPoints” field value.

    Note: When using mathematical expressions, only fields with a “Double” data type can be specified.

  • System.IterationPath

    This expression returns the value of the “System.IterationPath” field.

  • Scrum.BusinessValue * 2.5 / 100

    The above expression returns the “Scrum.BusinessValue” field multipled by 2.5 and divided by 100.

    Note: Calculations are made in left to right operand pair sequence. So the above example will be the result of “Scrum.BuinessValue” multiplied by 2.5 that is then divided by 100.

Siblings

Transition rules can include a collection of “Sibling” conditions. Siblings are work items that share a common linked target work item. For example in our “Make PBI Deleted” scenario, we specify that all work item Sibs of type “Sprint Backlog Item” that are linked to the target PBI with by a “Scrum.ImplementedBy” linkage, must also be in a state of “Deleted”. From the PBI point of view, this means that all my linked SBTs must be in a state of “Deleted” before this rule can be applied.

You can add multiple sibling conditions that can the reference any work item type linked by any linkage type.

Sibling conditions also allow you to set a list of sibling states that exclude work items from comparison. This is useful in order to handle scenarios where some work items should be ignored.

Links

Next time I will delve into the Transition sister service; the Aggregation service.

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Crispin Parker's Blog said:

This post relates to Team Foundation Server and the Scrum for Team System process template. Previously

January 26, 2010 14:03
 

Kris Venk said:

This article gives an excellent walkthrough about the making changes to the transition services.

After making the desired changes to the Transition rules through Transition.xml , how do we get these changes to be applied to the existent template?

Do we have to import the new rules to our template or how do we go about it?

September 21, 2010 00:00
 

crispin.parker said:

@Kris - The rules are run by the event service and are global to all projects. The TFS IIS must be reset in order for rule changes to be detected. Otherwise rule changes will not be detected until the app pool is recycled.

Crispin.

September 21, 2010 09:25
 

Pavel Hritonenko said:

I want to transit Acceptance Tests to "ready to test" state when all linked PBI's tasks are done. It's possible to specify this rule?

November 2, 2010 13:46
 

Kris Venk said:

@ Pavel

Yes, it would be possible to specify this rule. I assume your Acceptance Tests & Sprint Backlog tasks are not directly linked and both are linked only through the PBI.

So the state changes of Tasks have to be transmitted to Acceptance tests through the PBI. I see a two pronged approach

The PBI might have coding tasks as well tasks to run acceptance tests. Firstly if you have fields in tasks to distinguish between coding tasks & tasks to run acceptance tests, once all coding tasks are complete then it could be communicated to PBI by setting the state of PBI to an intermediary state (say: All coding done) through a transition rule.

Secondly, another transition rule to change the state of acceptance tests to 'Ready to Test' state whenenver PBI's state is set to above intermediary state (e.g: All coding done).

November 15, 2010 22:01
 

Kris Venk said:

@ Crispin

I have a PBI implementing a SBT.

SBT Fields A, B are aggregating into PBI Fields X, Y respectively.

SBT field A aggregates into PBI field X in all states including ‘Not Started’ state.

SBT field B aggregates into PBI field Y in all states except ‘Not Started’ state as it is specified as an excluded state.

Whenever PBI field X changes, there is a transition rule to re-evaluate an expression to update PBI field P

Whenever PBI field Y changes, there are two transition rules to re-evaluate expressions to update PBI fields Q, R (Where R = Y-X). Expression to evaluate Q is independent of X unlike R.

When PBI field X is updated without updating PBI field Y atleast once (through aggregation rules), there seems to be an incorrect behavior which I am guessing is due to racing condition.

PBI Field P picks up the previous value of PBI field X instead of current value of PBI field X to evaluate its expression.

A change in PBI field X places the transition rule as 1st in the queue. When there is a need to update PBI field X again due to change in SBT field A, the aggregation rule is placed as 2nd in the queue.

Transition rule gets picked up from the queue to update PBI field P and then the aggregation rule is picked up to update PBI field X.

A change in PBI field X due to aggregation should and does place the transition rule to update PBI field P again. But, this doesn’t happen until the time an aggregation rule is placed in the queue again to be applied.

There seems to be a racing condition between Aggregation rules & Transition rules.

But when PBI field Y is updated atleast once because of the change of SBT field B, everything works correctly.

In this case, there are two aggregation rules applied to update PBI fields X, Y and 3 transition rules to update P, Q, and R.

After making the change to Y atleast once, the racing condition doesn’t happen even if there was a scenario like above with only 1 transition & aggregation rule.

This has started happening since I set the tfsRegService delay to ZERO seconds from 2 minutes. Do you think this could have spurred the racing condition problem?

November 19, 2010 05:28
 

Crispin Parker's Blog said:

A recent question in the Scrum for Team System Q &amp; A site has highlighted that there is a lack of

December 10, 2010 18:00
 

Paul Shippy said:

Any chance we could get an XSD for these xml formats? Intellisense would be nice.

Paul

February 4, 2011 20:26
 

Daniel Pfulg said:

Can the event service be used to propagate from custom work item types as well?

I am trying to propagate work hours reported in a custom work item type to their parent PBTs through the following rule:

<AggregateRule type="Sum">

   <WorkItemType source="Work Hours" target="Sprint Backlog Task" />

   <Link linktypename="Scrum.DoneBy" isforward="true"/>

   <Field source="BIT.WorkHours.WorkHours" target="BIT.WorkActual" />

   <ChangeNote>Sum of associated work hours calculated.</ChangeNote>

   <ExcludedSourceStates>

     <State>Deleted</State>

   </ExcludedSourceStates>

 </AggregateRule>

Linke Type:

<?xml version="1.0" encoding="utf-8"?>

<LinkTypes>

<LinkType ReferenceName="Scrum.DoneBy" ForwardName="Done By" ReverseName="Used For" Topology="Tree" />

</LinkTypes>

March 30, 2011 09:15
 

crispin.parker said:

@Daniel Pfulg,

Yes, you can create rules for any work item field including your own custom ones. The rule definition looks good to me. Check the field names carefuly, they are case sensitive. Without access to your schema changes I can't validate the rule entirely.

Also, you should restart the IIS service after altering the rules files. This clears that cached rules.

If you still have problems, email me at ScrumforTeamSystem@emc.com or head on over to the SfTS Q & A web site: http://www.scrumforteamsystem.com/QA

Crispin.

March 30, 2011 09:44
 

crispin.parker said:

@Paul Shippy,

Only just spotted your comment about the rule schemas. If you take a look inside the event service Transition and Aggregation assemblies, you'll find that schemas are included as embedded resources. Reflector is a handy tool.

If you can't find them, please drop me an email at ScrumforTeamSystem@emc.com and I will dig them out for you.

Crispin.

March 30, 2011 09:47
 

Daniel Pfulg said:

@crisptin.parker:

Thanks for your quick answer.

The problem was not in the aggregation rules but in the update event subscription that was filtering the "core" work item types. And I forgot to update that filter...

March 30, 2011 10:57
 

Kate said:

In my task template I have fields for original estimate, completed work and remaining work.  So that my developers don't need to remember to update the remaining work field I was wondering how I can set it up to compute this after they enter the completed work.

Thanks,

May 24, 2011 00:11
 

Michael said:

Hi Crispin,

we have customized our Requirement work items with some approval fields, so if the Requirements state is set Resolved the approver need to set their approval to "Yes". If all approvals were set to yes, the state should be Closed. Here the rule I have created, but it went to Closed even if one of the other approved fields was set to "No":

 <TransitionRule>

   <WorkItemTypeName source="Requirement" target="Requirement" />

   <Transition field="Common.Approved1" from="*" to="Yes" />

   <LinkType target="Self" />

   <ChangeNote>The requirement got approval.</ChangeNote>

   <EligibleTargetStates>

     <State>Resolved</State>

   </EligibleTargetStates>

   <Replacements>

     <Replacement targetfield="System.State" type="Specified">Closed</Replacement>

   </Replacements>

   <SiblingConditions>

     <SiblingCondition comparison="All" field="Common.Approved2" value="Yes" siblingtype="Requirement" link="Self" />

     <SiblingCondition comparison="All" field="Common.Approved3" value="Yes" siblingtype="Requirement" link="Self" />

   </SiblingConditions>

 </TransitionRule>

Is it possible to use the "Self" link in the SiblingCondition? Or have I done anything wrong?

Thanks

November 11, 2011 12:58

Leave a Comment

(required) 
(optional)
(required) 
Submit

This Blog

Syndication

News

Powered by Community Server (Personal Edition), by Telligent Systems