Search code examples
visual-studiotfsvisual-studio-2015operator-precedencealm

How to change operator precedence (first OR, then AND) in Team Foundation Queries?


Background:

Visual Studio 2015 allows to create queries on your work items, bugs etc. stored in the Team foundation server (TFS). There is a query editor where you add conditions like

enter image description here

which will return bugs in the current projects that are not closed and resolved. So far it works fine, the bugs are replicated from an external system (HP ALM) into TFS.

If I now want to restrict bugs being assigned to me only, I can use the "Assigned To" field and add it as contition, but ALM uses a different account which is tracked by the "HP ALM Assigned To" field.


So I want to create a condition like

(Team Project = @Project) AND (State <> Closed) AND (State <> Resolced)
AND (HP ALM Assigned To = "myALMID" OR Assigned To = @Me)

But as you can see the query editor does not allow to enter brackets, and the condition as it is shown above does not do the right thing, because it will evaluate as

(Team Project = @Project) AND (State <> Closed) AND (State <> Resolced)
AND (HP ALM Assigned To = "myALMID") 
OR Assigned To = @Me

which appears to be not the same - instead it shows all items assigned to @Me OR all items meeting the condition

(Team Project = @Project) AND (State <> Closed) AND (State <> Resolced)
AND (HP ALM Assigned To = "myALMID") 

because the AND operator takes precedence over OR.


Question:
What do I need to change so the query is working as expected?



Update: I tried it with grouping, as suggested by Daniel Mann, but that does also not return the results I want:

enter image description here

I tried to change the OR HP ALM Assigned To = "myALMID" to AND HP ALM Assigned To = "myALMID" but that still does not do it right.


Solution

  • Considering both hints from Cece - MSFT and Daniel Mann, I modified the query as follows:

    enter image description here

    You can see that now there are only 14 items returned, which is correct. The issue seems to be solved, thanks both - I upvoted you because you both contributed to the solution.

    Now let me summarize, what I learned from this:

    • The order in which the conditions appear seem to matter. I moved the group containing HP Assigned to and Assigned to to the top to be able to select only "OR" between them and grouped it together

    • I had the ALM ID in quotes, which is wrong - so I removed them.

    • I grouped the state conditions together (but I am not sure if that is required)

    What is a pity is that the query editor does not allow "Not In", only "Not In Group", so I had to repeat the "State" lines for each state I wanted to exclude.