4

I have few workitems which contain custom field called "Reference ID" is it possible to query using wiql on this custom field. Currently I am using the following approach:

//foreach project in TFS

//form the wiql

WorkItemCollection workItemCollection = workItemStore.Query(
                    " SELECT [System.Id], [System.WorkItemType]," +
                    " [System.State], [System.AssignedTo], [System.Title] " +
                    " FROM WorkItems " +
                    " WHERE [System.TeamProject] = '" + tfsProject.Name +
                    "' ORDER BY [System.WorkItemType], [System.Id]");

//run a loop against the result set

//if workitem.Fields["Reference ID"]=required value

//do some tasks on this workitem

this approach is taking quite sometime since there are more than 1000 results.

my question: is it possible to add custom field also as a filter condition in the above query

balalakshmi
  • 3,968
  • 6
  • 40
  • 48

3 Answers3

2

Yes. You use the field name that's associated with the item. You can get this using the Process Explorer (TFS Power Tools) and opening the WorkItemType.

Here's an example we use today

Select Id from WorkItems where ([xxx.Ticket.OriginalTicketID] = '12345');
Robaticus
  • 22,857
  • 5
  • 54
  • 63
  • 1
    Alternatively, you can just hover over the label for the field in the work item editor and you should see a ToolTip with the field name. You can use that field name in your WIQL query. – Jim Lamb Jul 19 '10 at 13:52
  • True. I'm a bigger fan of using the internal name, personally-- but of course you're right. Both will work. – Robaticus Jul 19 '10 at 13:58
  • @Robaticus, You mean "Process Editor" under the tools menu. – Ashish Gupta Jul 06 '11 at 00:47
1

If you do not have access to TFS Power Tools or the ability to install it, then you can also use the DisplayForm property of the Work Item Object.

myItem = Workitem.GetWorkItem("12345")
myItem.DisplayForm

DisplayForm returns an XML containing all the Field Names and Properties. You could look up the XML by label and get the corresponding Control FieldName.

myItem.Fields.Item("Custom.FieldName")
Vinay
  • 954
  • 8
  • 13
0

Sure, just add the name of the custom field.

Jim Lamb
  • 25,355
  • 6
  • 42
  • 48