Answered by:
Retreive TFS TASKS to a TFS USER

Question
-
I am trying to retrieve all the tasks assigned to a particular user in the TFS programmatically.
Scenario: I want all the users to be populated in the dropdown list and when I select a user it should display all the tasks assigned to that user in a grid view.
This is the query :
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]");
and for the dropdown listforeach (WorkItem workItem in workItemCollection) { ddlUser_List.Items.Add(new ListItem(Convert.ToString(workItem.AssignedTo))); }
But this is not returning "AssignedTo" field which I want to populate in the dropdownlist.Is there any way to do that.
KingCobra [BalaVikram]Monday, August 3, 2009 12:58 PM
Answers
-
Hi,
First, you can change the query .
WHERE [System.TeamProject] = '" + tfsProject.Name + " & [System.AssignedTo] = " + Username
or change the property to Field - workItem.Fields["System.AssignedTo"].ToString()
foreach (WorkItem workItem in workItemCollection)
{
ddlUser_List.Items.Add(new ListItem(Convert.ToString(workItem.Fields["System.AssignedTo"].ToString())));
}
Please mark the replies as answers if they help and unmark them if they provide no help.
My blog: blogs.microsoft.co.il/blogs/shair- Proposed as answer by Shai Raiten Tuesday, August 4, 2009 5:34 AM
- Unproposed as answer by KingCobra Tuesday, August 4, 2009 6:49 AM
- Marked as answer by KingCobra Tuesday, August 4, 2009 6:49 AM
Tuesday, August 4, 2009 5:33 AM -
Thanks Shai Raiten,
Your code did work after a small change
foreach (WorkItem workItem in workItemCollection) { ddlUser_List.Items.Add(new ListItem(Convert.ToString(workItem.Fields["System.AssignedTo"].Value))); }
How is a task assigned to a user (how is Task related to a staff in database of TFS, like Task ID to Staff ID / task ID to a SID )?????
Are there any primary key on Staff table like Staff ID that we can rely on coding instead of using Assigned TO which is a text. User always can change the display name and user name.
Here is what I want! Have 2 drop downs, first will have TFS user names, second empty. Once the user selects a user name in the first drop down, second drop down should be populated with the tasks of the selected user!
KingCobra [BalaVikram]- Marked as answer by KingCobra Tuesday, August 4, 2009 6:49 AM
Tuesday, August 4, 2009 6:47 AM
All replies
-
Hi,
First, you can change the query .
WHERE [System.TeamProject] = '" + tfsProject.Name + " & [System.AssignedTo] = " + Username
or change the property to Field - workItem.Fields["System.AssignedTo"].ToString()
foreach (WorkItem workItem in workItemCollection)
{
ddlUser_List.Items.Add(new ListItem(Convert.ToString(workItem.Fields["System.AssignedTo"].ToString())));
}
Please mark the replies as answers if they help and unmark them if they provide no help.
My blog: blogs.microsoft.co.il/blogs/shair- Proposed as answer by Shai Raiten Tuesday, August 4, 2009 5:34 AM
- Unproposed as answer by KingCobra Tuesday, August 4, 2009 6:49 AM
- Marked as answer by KingCobra Tuesday, August 4, 2009 6:49 AM
Tuesday, August 4, 2009 5:33 AM -
Thanks Shai Raiten,
Your code did work after a small change
foreach (WorkItem workItem in workItemCollection) { ddlUser_List.Items.Add(new ListItem(Convert.ToString(workItem.Fields["System.AssignedTo"].Value))); }
How is a task assigned to a user (how is Task related to a staff in database of TFS, like Task ID to Staff ID / task ID to a SID )?????
Are there any primary key on Staff table like Staff ID that we can rely on coding instead of using Assigned TO which is a text. User always can change the display name and user name.
Here is what I want! Have 2 drop downs, first will have TFS user names, second empty. Once the user selects a user name in the first drop down, second drop down should be populated with the tasks of the selected user!
KingCobra [BalaVikram]- Marked as answer by KingCobra Tuesday, August 4, 2009 6:49 AM
Tuesday, August 4, 2009 6:47 AM -
Hi,
Try reading my post about TFS API Part 4: Get TFS User List (Mail, Sid, Account, Domain)
This will help you to get user Disply Name and Sid (and more) .
For what you want AssignedTo is fine, you don't need to search Sid in database.
Let me know if you need additional information.
Thanks
Please mark the replies as answers if they help and unmark them if they provide no help.
My blog: blogs.microsoft.co.il/blogs/shair- Proposed as answer by Shai Raiten Tuesday, August 4, 2009 8:03 AM
- Edited by Shai Raiten Tuesday, August 4, 2009 11:07 AM Link Fix
Tuesday, August 4, 2009 8:03 AM -
The Link does not open ?
Found by visting your blog.
Thanks for the help. Will check.
KingCobra [BalaVikram]Tuesday, August 4, 2009 10:22 AM -
How do I get the tasks for a given display name say for example "shair" from your screen shot in the mention blog article ? Once the Account name is selected from the account drop down, I want to display the tasks assigned to that Account name. I see that in my TFS, AssignedTo is sometimes the Account name and some times Account Display name!!
KingCobra [BalaVikram]Tuesday, August 4, 2009 10:31 AM -
Hi,
All Users are coming direclty from Active Directory, if some users dosn't have Disply Name this is something your IT can fix.
From my blog you can download the demo project and see.
THanks
Please mark the replies as answers if they help and unmark them if they provide no help.
My blog: blogs.microsoft.co.il/blogs/shairTuesday, August 4, 2009 11:09 AM -
Great, that makes it more clear. So TFS is not a repository for User but instead ADS is the user store. Thats a great start then , thanks.
You made into by blog -> blog list too... Congrats.... here
KingCobra [BalaVikram]Tuesday, August 4, 2009 11:17 AM -
Thanks!
Good Luck
Please mark the replies as answers if they help and unmark them if they provide no help.
My blog: blogs.microsoft.co.il/blogs/shairTuesday, August 4, 2009 3:17 PM