none
Working with WorkItem Object Model need help!

    Question

  • Hello all,

    I'm trying to create a simple GridView in ASP.NET 2.0 that binds itself to the TFS workItems.
    So far everything seems to work well.

    I've created a class that holds one method called GetWorkItems it somewhat looks like this:

    public WorkItemCollection GetWorkitems(string sortExpression, string RoleName)
    {
    TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(DomainName);
    tfs.Authenticate();

    WorkItemStore
    store = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
    // Check if we have any projects
    if (store.Projects.Count <= 0)
    return null;

    //Get the proper Team Project
    Project project = store.Projects[TeamProjectID];
    if (project.StoredQueries.Count <= 0)
    return null;

    string
    wiqlQuery = "SELECT [System.ID], [MyCompany.UserName], [System.Title], FROM WorkItems WHERE [System.WorkItemType] = 'Bug'";

    // execute the query and retrieve a collection of workitems
    WorkItemCollection workitems = store.Query(wiqlQuery);

    return workitems;
    }

    NOTE:DomainName and TeamProjectID are variable being populated from the web.config file

    Now, so far nothing too complicated, I can drag a GridView control and bind it to my GetWorkitems() method. When Editing Columns I do not see the field [MyCompany.UserName] that I'm asking in my Query. More importantly, I seel all kinds of field I'm not even asking for(look at wiqlQuery).

    Perhaps I'm not binding it to the right thing?

    So I guess my first question is, how can I obtain/get the [MyCompany.UserName] field in the Available fields?

    Second question, If I enable sorting, then I'll have to implement my own and not being fully comfortable with the WorkItem Object Model, can anyone point me in the direction of an example?

    All of this is coded inside and aspx page.
    Thanks in advance for any help!

    Sincerely

    Vince

    Thursday, February 16, 2006 10:00 PM

Answers

  • Ok so I finally figured out a workaround in order to achieve what I wanted.

    My initial problem was this:
    I had a GetWorkItems method returning a WorkItemCollection. This method was bound to a GridView control in an aspx page. At design time, I couldn't see the *custom fields* that I was asking for in my wiqlQuery and for some reason, couldn't print them at runtime.

    The workaround was to fill in a dataset and then make the GetWorkItems method return a dataset. Then the GridView would be bound to a dataset allowing me to view the *custom fields*

    Here's the final result:

    public Dataset GetWorkitems(string sortExpression, string RoleName)
    {
    TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(DomainName);
    tfs.Authenticate();

    WorkItemStore
    store = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
    // Check if we have any projects
    if (store.Projects.Count <= 0)
    return null;

    //Get the proper Team Project
    Project project = store.Projects[TeamProjectID];
    if (project.StoredQueries.Count <= 0)
    return null;

    string
    wiqlQuery = "SELECT [System.ID], [MyCompany.UserName], [System.Title], FROM WorkItems WHERE [System.WorkItemType] = 'Bug'";

    // execute the query and retrieve a collection of workitems
    WorkItemCollection workitems = store.Projects[TeamProjectID].Store.Query(wiqlQuery);

    // Create dataset and start adding the workitem values you need to it
    WorkItemListDataset
    w = new WorkItemListDataset();
    w.WorkItem.BeginLoadData();

    foreach (WorkItem workitem in workitems)
    {
    w.WorkItem.AddWorkItemRow( workitem.Id,workitem.Title,workitem.AreaPath,workitem.Fields[
    "Feature"].Value.ToString(),workitem.Fields["Severity"].Value.ToString(),workitem.CreatedDate,workitem.Fields["UserName"].Value.ToString(),workitem.State,workitem.Reason);
    }

    w.WorkItem.EndLoadData();

    return w;

    }

    NOTE: I've omitted the complete wiqlQuery to make is simpler but the amount of fields I'm asking in the SELECT statement should be the same as the fields in the dataset.

    That's it!
    Vince



    Friday, February 17, 2006 8:10 PM

All replies

  • Ok so I finally figured out a workaround in order to achieve what I wanted.

    My initial problem was this:
    I had a GetWorkItems method returning a WorkItemCollection. This method was bound to a GridView control in an aspx page. At design time, I couldn't see the *custom fields* that I was asking for in my wiqlQuery and for some reason, couldn't print them at runtime.

    The workaround was to fill in a dataset and then make the GetWorkItems method return a dataset. Then the GridView would be bound to a dataset allowing me to view the *custom fields*

    Here's the final result:

    public Dataset GetWorkitems(string sortExpression, string RoleName)
    {
    TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(DomainName);
    tfs.Authenticate();

    WorkItemStore
    store = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
    // Check if we have any projects
    if (store.Projects.Count <= 0)
    return null;

    //Get the proper Team Project
    Project project = store.Projects[TeamProjectID];
    if (project.StoredQueries.Count <= 0)
    return null;

    string
    wiqlQuery = "SELECT [System.ID], [MyCompany.UserName], [System.Title], FROM WorkItems WHERE [System.WorkItemType] = 'Bug'";

    // execute the query and retrieve a collection of workitems
    WorkItemCollection workitems = store.Projects[TeamProjectID].Store.Query(wiqlQuery);

    // Create dataset and start adding the workitem values you need to it
    WorkItemListDataset
    w = new WorkItemListDataset();
    w.WorkItem.BeginLoadData();

    foreach (WorkItem workitem in workitems)
    {
    w.WorkItem.AddWorkItemRow( workitem.Id,workitem.Title,workitem.AreaPath,workitem.Fields[
    "Feature"].Value.ToString(),workitem.Fields["Severity"].Value.ToString(),workitem.CreatedDate,workitem.Fields["UserName"].Value.ToString(),workitem.State,workitem.Reason);
    }

    w.WorkItem.EndLoadData();

    return w;

    }

    NOTE: I've omitted the complete wiqlQuery to make is simpler but the amount of fields I'm asking in the SELECT statement should be the same as the fields in the dataset.

    That's it!
    Vince



    Friday, February 17, 2006 8:10 PM
  • Just as FYI for me if you don't mind, are you trying to create a web access app for workitems?  I was going to create my own too, but found that there was already one created called TeamPlain.
    Tuesday, February 21, 2006 7:16 PM
  • Yes I am, actually its been on stand by for the past month or so and I'm now continuing working on it.

    I'm also aware of TeamPlain and had discussions with one of the dev over there. Since we deployed at our customers all we need is a simple web bug tracker linked directly to VSTS.

    We could've bought our own bug tracker instead of creating one and then link the Tables somehow, but since we didn't need a full fledge bug tracker with reports and what not we created our own little aspx page.

    Nothing too complicated just enough for our needs.

    As for TeamPlain, I'm not sure if it is customizable, maybe now it is but back then it wasn't, and we didn't want our clients to view tasks, and other team projects and ...and...and...

    Hence why we created our own!

    Plus it allowed us to play around with the Object Model of the workitems which is fun!

    But thanks, I'm definitely keeping an eye open for TeamPlain since I don't usually like to reinvent the wheel.

    Sincerely

    Vince

    Wednesday, February 22, 2006 2:50 PM
  • Hi,

    What is the namespce to be included for WorkItemListDataset.

    Thanks

    Mike

    Monday, April 24, 2006 10:45 PM
  • Hey Mike,

    WorkItemListDataset is a custom dataset that he created as part of his project.  This contains a DataTable called WorkItem, which he's then filling from the WorkItemCollection data.

    -Larry

     

    Tuesday, April 25, 2006 11:47 AM
  • Thanks for the reply Larry.

    Can anyone tell me where I can find examples to build web applications that can connect to Team Foundation Server, view and add work Items? I want to build a simple application to do certain tasks. TeamPlain would be overkill for me.

    Thanks

    Tuesday, April 25, 2006 5:24 PM