Search code examples
tfswiql

Update to TFS custom field - optimization


I wanted to access TFS data via TFS API and WIQL using a custom field in WIQL where clause:

string wiqlQueryDoorsProxy = "Select * from WorkItems where ([Work Item Type] = 'DoorsProxy' AND [Object Id] = '\" + requirementId + "\')";

where [Object Id] is the custom field. But TFS API gave exception message:

"TF51005: The query references a field that does not exist. The error is caused by «[Object Id]»."

The field definition has name = "Object Id" and reference name = "DoorsTool.DoorsArtifactType.ObjectId". I tried both Object Id and DoorsTool.DoorsArtifactType.ObjectId in the WIQL. Same result.

I changed the code as follows and it worked perfectly:

string wiqlQueryDoorsProxy ="Select * from WorkItems where ([Work Item Type] = 'DoorsProxy' )"; WorkItemCollection witCollectionDoorsProxy = wiStore.Query(wiqlQueryDoorsProxy); foreach (WorkItem workItemDoorsProxy in witCollectionDoorsProxy) { workItemDoorsProxy.Open(); if (workItemDoorsProxy.Fields["Object Id"].OriginalValue.ToString() == requirementId) { ... } }

But now the performance is bad.

What can I do. The problem looks similar to this but still I cannot solve the problem based on that discussion.


Solution

  • The way way is to create the query that you want in visual studio first. Once you have It working you can "save as" to local disk and open It in notepad. You can just copy the query from there.