Search This Blog

Showing posts with label WorkItemStore. Show all posts
Showing posts with label WorkItemStore. Show all posts

Thursday, December 06, 2007

TF20015: The field 'xxx' contains a value that is not in the list of supported values.

While trying to save a work item in TFS you might be facing a problem doing it when the error TF20015 is raised. This error is raised when you are trying to enter values that are not part of the allowed values of the field. The strange thing is that it can happen although the value was already saved before to the work item and the field is disabled. As a result you cannot change the value and therefor cannot save the work item. So why does it happen? I faced this problem in two cases:


  1. The user in one of the fields (which is implementing the valid user value list as the allowed values for the field) was renamed or deleted.

  2. The work item schema was changed in a way that made some of the existing work items have illegal values. For example, if you made one of the fields mandatory trough all of the work flow and you have some work items with a null value in the field.

So, how can you fix it?


There are 2 ways to do it:



  1. Changing the work item schema temporarily so the field won't be disabled and then you can change the value.

  2. Write some code the change the field value:

Here's a code sample on how to update work item field values:


public void UpdateWorkItem(string serverUri, int id, string fieldName, string fieldValue)
{
TeamFoundationServer tfs = new TeamFoundationServer(serverUri);
tfs.EnsureAuthenticated();
WorkItemStore wis = tfs.GetService(typeof(WorkItemStore)) as WorkItemStore;
WorkItem workItem = wis.GetWorkItem(id);
workItem.Open();
workItem.Fields[fieldName].Value = fieldValue;
workItem.Save();
}


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.

Wednesday, May 30, 2007

Cropper TFS Work Item Plugin

It's been a while since I wrote here. Anyway, I hope this post will compensate for it. I read this week a post about SnagIt! integration with TFS. Since I use Cropper I've decided to write a plugin for TFS.
The plugin enables you to capture images directly to a new TFS work item attachments field. You can also add an attachment to an existing work item. You can download it from here. Read the read me file for installation guide and how to use it.
The plugin uses the WorkItemFormControl to edit the work item. I will explain in future posts on how to use it.
I'm planning to add the sources to Cropper Plugins project in CodePlex.
The plugin is in it's early stages. I would be happy to hear your comments.

Thursday, April 12, 2007

Extracting Images from Work Items Attachments

In this example I will show how to use the WorkItemStore interface. This example will execute a stored query on the work items database and will extract the attachments from the work items returned from the query. This is a good training for working with the WorkItemStore interface.

private void ExtractWorkItemsAttachments(string teamFoundationServer, string teamProject, string storedQuery,

string saveTo)

{
//Logon to the server and create the needed objects
TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(teamFoundationServer);
tfs.EnsureAuthenticated();
WorkItemStore store = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
Project tfsProject = store.Projects[teamProject];
StoredQueryCollection sqc = tfsProject.StoredQueries;
string querystring;
//Search for the query
foreach (StoredQuery query in sqc)
{
if (query.Name == storedQuery)
{
//Execute the query
querystring = query.QueryText;
querystring = querystring.Replace("@project", "'" + tfsProject.Name + "'");
WorkItemCollection workItems = store.Query(querystring);
//Extract the attachments
foreach (WorkItem workItem in workItems)
{
if (workItem.Attachments.Count > 0)
{
foreach (Attachment attachment in workItem.Attachments)
{
//Using WebClient to download the attachment
WebClient webClient = new WebClient();
webClient.Credentials = CredentialCache.DefaultCredentials;
string fileName = Path.Combine(saveTo, attachment.Name);
webClient.DownloadFile(attachment.Uri.AbsoluteUri, fileName);
}
}
}
}
}
}