Understanding Action for state transition in Details

In this blog series I will explain TFS Process Customization in details, I will try to explain what happen behind the scene, show common errors that happen when we perform customization and answer many questions that could come for anyone perform TFS Process Customization, this series consist of following parts:

Each part consist of one or many sections as needed.

=================================================================================

Part 2 – Understanding Action for state transition in Details

[youtube=http://youtu.be/3eqXzAJ0ri4 ]
Action is a very confused concept for many people, what is action? Can I create a custom action? How to use action or custom action?

So in this post I will try to simplify what is really meaning by Action and how does it work?

So the first question is: what is Action?

It’s just a unique string that used as a flag that added in the transition between states to be used by third party tools, so we can know which is the current state and which is the next state for given action in a work-item.

Just imagine that I have create a small application that has only one button that list some work-items from different types of work-items (Bug, Task, Change Request, Etc)

Change Sate based on action transation

I just want when I click on the button all work-items from Type-1 changed from Sate-1 to State-2 but if the work-items in State-2 or State-3, it remains in the same state.

I also need all work-items from Type-2 changed from Sate-2 to State-3 but if the work-items in State-1 or State-3,  it remains in the same state ……….. to do that I need to go to the WID (Work Item Definition) for these 2 types of work-items and in the transition between the desired states I will put my custom action, and this action can be retrieved by TFS SDK afterwards.

Work-item type 1

[code language=”xml”]
<TRANSITION from="State-1" to="State-2">

<ACTIONS>

<ACTION value="Radwan.Actions.CustomAction">

</ACTIONS>

</TRANSITION>
[/code]

Work-item type 2

[code language=”xml”]
<TRANSITION from="State-2" to="State-3">

<ACTIONS>

<ACTION value="Radwan.Actions.CustomAction">

</ACTIONS>

</TRANSITION>
[/code]

Work-item type 1
Action
Work-item type 2

Action-2
So when I get next state using TFS API or (SDK) with this custom action I can know which work-item in the desired state so I can advance it to the next state and if the work-item doesn’t has the action in the transition, that’s meaning I don’t need to advance its state.

The following code get some work-items and iterate over them and get next state for my custom action and print next state if it found that action.

[sourcecode language=”csharp”]
WorkItemCollection witCollection = workItemStore.Query(wiqlQuery);
foreach (WorkItem workItem in witCollection)
{

Console.WriteLine("Next State for {0} is {1}", workItem.Title,
workItem.GetNextState("Radwan.Actions.CustomAction"));

}
[/sourcecode]

This will told me if my flag (Custom Action) is there or not and what is the next state so I can advance (change) the state.

[sourcecode language=”csharp”]
class Program
{
static void Main(string[] args)
{
RetrieveWorkItems();
Console.Read();
}
public static void RetrieveWorkItems()
{
var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new
Uri("http://VSALM:8080/TFS/Collection"));
var workItemStore = tfs.GetService<WorkItemStore>();

var wiqlQuery = String.Format(@"Select [State], [Title] From
WorkItems Where [Work Item Type] = ‘Task’ Order By [State] Asc,
[Changed Date] Desc"); ;

WorkItemCollection witCollection = workItemStore.Query(wiqlQuery);
foreach (WorkItem workItem in witCollection)
{
Console.WriteLine("ID: {0}", workItem.Id);
Console.WriteLine("Title: {0}", workItem.Title);
Console.WriteLine("Next State for {0} is {1}", workItem.Title, workItem.GetNextState("Microsoft.VSTS.Actions.Checkin"));
Console.WriteLine("Next State for {0} is {1}", workItem.Title, workItem.GetNextState("Radwan.Actions.CustomAction"));
Console.WriteLine("");
}
}
}

[/sourcecode]

Automate field assignments based on State, Transition, or Reason
Work item Action list

Obtain possible next states of a work item programatically?

Changing State according to a field’s value

New State for TFS 2012

WorkItem.GetNextState Method

 

Share This: