Search This Blog

Showing posts with label WorkItemType. Show all posts
Showing posts with label WorkItemType. Show all posts

Monday, December 03, 2007

Set Work Item Type field allowed values when another field value changes

I was asked once by a friend if there's a way to filter the allowed values of a field when another field value changes. Well, the solution is not exactly as we think about filtering but more like a switch/case mechanism.

Let's take for example 2 fields that implement OS Platform & Version selection:

Windows --> XP, 2003 Server, Vista

Linux --> Ubuntu, Red Hat, Suse

Mac --> OS X 10.0, OS X 10.5

To implement this in the work item type definition file we need to define 2 fields. The xml should look like this:

<FIELD
type="String"
name="OS Platform"
refname="MyFields.OSPlatform">

<ALLOWEDVALUES>

<LISTITEM
value="Windows" />

<LISTITEM
value="Linux" />

<LISTITEM
value="Mac" />

</ALLOWEDVALUES>

</FIELD>

<FIELD
type="String"
name="OS Version"
refname="MyFields.OSVersion">

<WHEN
field="MyFields.OSPlatform"
value="Windows">

<ALLOWEDVALUES>

<LISTITEM
value="XP" />

<LISTITEM
value="2003 Server" />

<LISTITEM
value="Vista" />

</ALLOWEDVALUES>

</WHEN>

<WHEN
field="MyFields.OSPlatform"
value="Linux">

<ALLOWEDVALUES>

<LISTITEM
value="Ubuntu" />

<LISTITEM
value="Red Hat" />

<LISTITEM
value="Suse" />

</ALLOWEDVALUES>

</WHEN>

<WHEN
field="MyFields.OSPlatform"
value="Mac">

<ALLOWEDVALUES>

<LISTITEM
value="OS X 10.0" />

<LISTITEM
value="OS X 10.5" />

</ALLOWEDVALUES>

</WHEN>

</FIELD>

The version field contains WHEN rule for each platform. The result is a field that changes in real time when the parent field value changes.

You don't have to write the xml in order to achieve this. You can use the "Process Template Editor" which is part of the Team Foundation Server power tools to easily add fields and rules to you work item.

Thursday, November 29, 2007

TFSQueryExplorer

I have a new project in CodePlex named TFSQueryExplorer. It is a Visual Studio addin that looks like the Team Explorer tool window but it is dedicated to the management of queries and work items. There are a lot of cool features like manage queries in tags/folders, quick search, integration with the work item templates power tool and so on. The project is an example for using Visual Studio SDK and Team System API. I hope that you'll find it useful.

Tuesday, July 17, 2007

How to Expose the Work Item Editor Control

I've used this while writing the Cropper TFS Work Item plugin. I needed a way to edit or create a new work item. The WorkItemFormControl located under the Microsoft.TeamFoundation.WorkItemTracking.Controls namespace is the same control used by Visual Studio work item plugin and also by the process template editor (which was the way I found how to use it).

Here's an example for creating a new work item with the control.

First we need to connect to a Team Foundation Server and obtain the WorkItemStore service:

TeamFoundationServer tfs = new TeamFoundationServer(serverName);
tfs.EnsureAuthenticated();
WorkItemStore wis = tfs.GetService(typeof(WorkItemStore)) as WorkItemStore;

After doing so we can now create the WorkItemFormControl:

WorkItemFormControl wifc = new WorkItemFormControl();

The WorkItemFormControl has a string property named FormDefinition. We need to set this property with an XML defining the work item type that we want to use. To do so we use the WorkItemStore service:

WorkItemType wit = wis.Projects[teamProjectName].WorkItemTypes["Bug"];

This will return the the Bug work item type.

After doing so we can use the WorkItemType to set the FormDefinition property:

XmlDocument xmlDocument = wit.Export(false);
wifc.FormDefinition = xmlDocument.InnerXml;

Now we can use the WorkItemFormControl with a newly created work item or an existing one:

WorkItem wi = new WorkItem("Bug"); or WorkItem wi = wis.GetWorkItem(bugId);
wifc.Item = wi;

To show the control embed it to a form or a panel on a form.