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


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

<TRANSITION from="State-1" to="State-2">

<ACTIONS>

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

</ACTIONS>

</TRANSITION>

Work-item type 2

<TRANSITION from="State-2" to="State-3">

<ACTIONS>

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

</ACTIONS>

</TRANSITION>

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.

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"));

 }

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.

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("");
 }
 }
 }

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

 

TF400618: The reporting type of field in work item type conflicts with the reporting type of the existing field.


When I upgrade a server from TFS 2010 to TFS2013 I faced the following error

There are no process templates available with valid configuration settings for this team project.

TF400618: The reporting type of field “Filed name” in work item type “Work-Item type” conflicts with the reporting type of the existing field.

TF400618

This problem happen because the old project use a filed as reportable=”dimension”  but the new process template (Scrum 2013) doesn’t.

So all I need to do.

  1. Download the Scrum Process Template from TFS 2013
  2. Update the filed to be reportable=”dimension”
  3. Upload the process template and override the existing one

So now the 2 fileds are matching and it succeed

How to add an account to Service Accounts Group in TFS?


When I start working with TFS Integration Platform, I face the following error:

Microsoft.TeamFoundation.Migration.Tfs2010WitAdapter.PermissionException: TFS WIT bypass-rule submission is enabled. However, the migration service account 'Radwan' is not in the Service Accounts Group on server 
 at Microsoft.TeamFoundation.Migration.Tfs2010WitAdapter.TfsCore.CheckBypassRulePermission()
 at Microsoft.TeamFoundation.Migration.Tfs2010WitAdapter.TfsWITMigrationProvider.InitializeTfsClient()
 at Microsoft.TeamFoundation.Migration.Tfs2010WitAdapter.TfsWITMigrationProvider.InitializeClient()
 at Microsoft.TeamFoundation.Migration.Toolkit.MigrationEngine.Initialize(Int32 sessionRunId)

So how to add my account or the account that will be used to run TFS Integration Platform for the Service Accounts Group?

You can’t add accounts using the UI so we need to run a command line

From TFS Server as the following

C:\Program Files\Microsoft Team Foundation Server 12.0\tools>
\TFSSecurity.exe /g+ "Team Foundation Service Accounts"
n:domain\mradwan /server:http://vsalm

From Visual Studio client machine Server as the following

C:\Program Files\Microsoft Visual Studio Server 12.0\tools>
\TFSSecurity.exe /g+ "Team Foundation Service Accounts"
n:domain\mradwan /server:http://vsalm

Note: For sometimes you will have to type /server:http://vsalm:8080/tfs

Add account Service account group

Note: TFS Integration Platform 2012 can work with TFS 2013 but it needs the old object Model so just install Team Explorer 2012 or 2010 will solve the issue.

Do I need to remove Lab Management from a Collection when I Upgrade?


This is really a very important question, so the answer depends on some conditions, if you are upgrading to a different domain or if you will use a different SCVMM (System Center Virtual Machine Manager), you must delete the resources that are used by Lab Management from the collection database, this include virtual machines, templates, team project host groups, and team project library shares, otherwise you will keep them.

You will need to re-create the Lab Management assets after you finish the upgrade

To remove the Lab Management resources

You will use:

TFSConfig Lab /Delete /External

The following is the notification when you don’t delete them.

Note: this also applyed for moving collection to another server

Team Foundation Server could not tear down the deployment rig on environment in project. Delete the Visual Studio 2010 Team Foundation Build Agent associated with this environment manually using Team Foundation Server Administrator Console. Exception Details: TF30040: The database is not correctly configured. Contact your Team Foundation Server administrator.

Delete the Lab Management resources

Can’t keep cloned projects in both collections (original and cloned)


Sometimes you may want to clone your collection for many reason, we can use the following command:

C:\Program Files\Microsoft Team Foundation Server 12.0\
Tools>tfsconfig collection /attach /collectionName:ClonedFabrikam
collectionDB:vsalm\SQLExpress;TFS_FabrikamFiberCollection /clone

And remember: 

  • You will need to detach the collection first and make a copy of the DB
  • The /clone switch didn’t actually clone DB it just telling TFS Admin Console this is a cloned collection so please don’t start it :-)

Note 1:
It’s important to know that you can’t start the cloned collection until you delete the projects from the original or the cloned collection, so you can’t keep projects on both collection, otherwise you will face the following error:

TF253021:The following team project is duplicated in at least two team project collections:  The collection cannot start while the duplication exists. You must delete this project from all but one of the collections before the collection can be started. The project exists in the following collections: 

TF253021

Note 2:

It’s Important to know that you must detach the collection otherwise it will not appear when you try to attach, you can make the backup without detach if you are making upgrade from old version like 2010 or 2008.

Note 3:

For not detached collection you can use TFSConfig with Recover option but this only for TFS2010 but don’t use it with TFS2012 or TFS2013 as it’s deprecated

Fore more information:

Video for New Features in TFS 2013.2 (Update 2) CTP 1


Brian Harry just announced 2 weeks ago about VS/TFS 2013.2 (Update 2) CTP1, I really wanted to get close for the new features and enhancement so I decide to install that update and share my experience for the installation and the new features.

There is knowing issue about that update so it took from me sometimes to install and record my video, remember it’s not a Go live support.
Not-golive

Here is the video

Understanding TFS Process Customization in Details- Series


3 years ago I wrote a blog post about Customizing TFS Process 2010, this was a basic customization, today I will deep dive with more details about TFS Customization Process.

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 1 – Working with Fields

I will start by introducing working with fields, there are many questions come in our mind when we start working with fields like:

  • Why we need to create a filed?
  • What is happening when we create a new field?
  • Is the field exist per project or collection?
  • Can we using field multiple times for different work items?
  • Can we have 2 fields with same name? Or with the same reference name?
  • Can we change the data type of an existing field?
  • Can we know which fields are not used anymore?
  • If we delete a filed from WID (Work Item Definition) or Global Workflow is it deleted from our DB?
  • Can we delete fields?
  • If I remove a field from WID and it has data in DB and return it back did I get the data back?
  • Can we enhance queries speed using our new fields?

So first, here is the existing reference for all fields that come with TFS, Work item field reference for Visual Studio ALM

  • Why we need to create a filed?

This is very important question because some people think that we create a field so we can add that field to the Work-Item form so user can enter data for it, yes that’s true but also sometimes we create filed without needing to show it on the form, maybe we will track some values in that filed during the workflow or maybe during the form data changes, so not every fields added will be added to the form.

  • What is happening when we create a new field?

We simply create a new field by open TFPT (Microsoft Visual Studio Team Foundation Server 2013 Power Tools ) Process Editor from Visual Studio and open a Work Item from file or from server and go to Fields and click New, we will need to provide Name and Reference Name,  also we will need to choose a Data Type as well.

2-12-2014 3-34-53 PM

We can also create fields by export WID (Work Item Definition) add new field and then import WID to the desired project, or by using Global Workflow Definition, or the GUI using Process Editor and click save.

As we can see in the follwing  WID (Work Item Definition), it has 3 sections FIEDLS, WORKFLOW and FORM, adding field will add this field to the FIELDS section with FIELD element and all rules will be inside that element

<WORKITEMTYPE name="Product Backlog Item">
<FIELDS>
<FIELD name="Radwan Value3" refname="Radwan.Value3" type="String">
<Rule1></Rule1>
<Rule2></Rule2>
</FIELD>
</FIELDS>
<WORKFLOW>.....</WORKFLOW>
<FORM>.....</FORM>
</WORKITEMTYPE>

TFS will create that field inside 11 views to track Work Items changes and updates for that field and of course other fields as well but this only happen for all data type expect PlainText and HTML because they are not a physical columns in the DB like the other fields and this is why we only be able to change data types between PlainText and HTML as we will see later on this post.

2-12-2014 3-57-35 PM

These are the views  affected by creating 2 fields

2-12-2014 1-55-56 PM

 So let’s see some of that views in more details

View  WorkItemChanges
It keeps all the recodes of the WI changes except (without) the last update and it shows under each field the last value if the field changed or NULL if the field not changed, in other word it only shows values if this field changed in the last update, see the following image. 

2-12-2014 1-52-02 PM

View  WorkItemsUpdate

It keeps the last record of the WI changes, see the following image.
2-12-2014 2-11-05 PM-2

 View  WorkItemsLatestUsed

It keeps the last record of the WI changes

View  
WorkItemsAreUsed

It keeps the last record of the WI changes

View  WorkItemsQueryEverable

It keeps all the recodes of the WI changes including the last one.
2-12-2014 1-47-29 PM-3

  • Is the field exist per project or collection?

Fields are created per DB or TFS Collection, see the following image that illustrate the scope of different object across TP and TP Collection.

IC548825
2-12-2014 2-06-30 PM

So let’s see some rules that you need to consider while creating a new field in TFS Work Item

  • Can we using field multiple times for different work items?
  • Can we have 2 fields with same name? Or with the same reference name?

You can add the same field for different Work Items as long as needed but you need to use the same Reference Name and Name that you used in the first time create that field, TFS will understand that it’s the same field you created earlier and will not create a new field, you can have different values for the following attributes for the same filed inside different Work Item like:

  • Label or the name that displays on the work item form
  • The help text
  • The allowed values within a drop-down menu

You can’t have 2 fields with the same Reference Name per collection, and if you try to save a field that already exists with the same Reference Name but you try that with different Name, TFS will worrying you that you are trying to rename an existing field, you will see the following error.
2-12-2014 3-06-26 PM

Also you can’t have 2 fields with the same Name per collection, and if you try to save a field that already exists with the same Name but you try that with different Reference Name, TFS will worrying you that this Name already used with an existing field or Reference Name, you will see the following error.
2-12-2014 3-20-52 PM

  • Can we change the data type of an existing field?

If you add a field with certain data type and saved that field, you can’t change its data type and if you try to do that you will see the following error message.

2-13-2014 11-34-45 AM

You can only change data type from HTML to PlainText or PlainText to HTML and you can’t even use Process Editor (GUI) to do that, it’s only available from the command line tool (witadmin changefield) we can use also that command for make the field synchronizing with Active Directory in case that filed store names like created by, approved by so instead of just using static text the text will be sync with AD.

witadmin changefield /collection:http://vsalm:8080/tfs/MyCollection
/n:Radwan.Value1 /type:PlainText

  • Can we know which fields are not used anymore?

We can use (witadmin listfields) to list all fields and this will show if the filed are used or not and also we can use the option of (/unused) to only display fields that are not used

  • If we delete a filed from WID (Work Item Definition) or Global Workflow is it deleted from our DB?
  • Can we delete fields?
  • If I remove a field from WID and it has data in DB and return it back did I get the data back?

Removing a field from WID or Global workflow will not delete the field form the DB even if it has not any data.

We use (witadmin deletefiled) to delete fields from the DB but first we need to make sure that this field are not used, we using  (Witadmin listfields) to know that and then remove that filed from the form (Layout) if it exist and then remove it from the field list in the WID.

If we remove the filed form WID without deleting it using  (witadmin deletefiled) then we can return it back as all data are still there in the DB and linked to WI by ID

Remember if you delete a field, you will need to rebuild TFS Data warehouse to update the reports by removing its value

  • Can we enhance queries speed using our new fields?

We have a command (witadmin indexfiled) we can use to index our field so it can increase quires speed using this field.