3

Retrieving User Stories assigned to me

WorkItemStore _WorkItemStore = (WorkItemStore) __ProjectCollection.GetService(typeof(WorkItemStore));                      
String _Query = @"SELECT [System.Id] FROM WorkItems where [Assigned to] = @Me AND [Work Item Type] = 'User Story'";
WorkItemCollection _Collection = _WorkItemStore.Query(_Query);

A User Story can have either a Task or Bug work item type assigned to it as a child item. The bugs / tasks then have changesets linked to them.

Is it possible for me to retrieve a list of these changesets which are attached to the tasks / bugs which are child items of these user stories?

Jack
  • 15,614
  • 19
  • 67
  • 92

1 Answers1

2

I'm adding this answer as an alternative, however I'd still love to know if it's possible to achieve this same result with a WIQL query.

A recursive function that i've written to retrieve all changesets for a userstory which are associated to any child work items.

public List<Changeset> Query(int id, List<Changeset> associatedChangesets)
{            
    WorkItemStore _WorkItemStore = (WorkItemStore) __ProjectCollection.GetService(typeof(WorkItemStore));            
    WorkItem _WorkItem = _WorkItemStore.GetWorkItem(id);

    List<Changeset> _AssociatedChangesets;

    if (associatedChangesets == null)
    {
            _AssociatedChangesets = new List<Changeset>();
    }
    else
    {
        _AssociatedChangesets = associatedChangesets;
    }

    foreach (Link _Link in _WorkItem.Links)
    {
        RelatedLink _RelatedLink = null;
        ExternalLink _ExternalLink = null;

        if(_Link is RelatedLink)
        {
            _RelatedLink = (RelatedLink)_Link;
        }
        else if(_Link is ExternalLink)
        {
            _ExternalLink = (ExternalLink)_Link;
        }

        if (_ExternalLink != null)
        {
            ArtifactId _Artifact = LinkingUtilities.DecodeUri(_ExternalLink.LinkedArtifactUri);
            if (String.Equals(_Artifact.ArtifactType, "Changeset", StringComparison.Ordinal))
            {                        
                _AssociatedChangesets.Add(__VersionControl.ArtifactProvider.GetChangeset(new Uri(_ExternalLink.LinkedArtifactUri)));
            }
        }

        if (_RelatedLink != null)
        {
            if (String.Equals(_RelatedLink.LinkTypeEnd.Name, "Child", StringComparison.Ordinal))
            {
                associatedChangesets = Query(_RelatedLink.RelatedWorkItemId, _AssociatedChangesets);
            }
        }
    }
    return associatedChangesets;
}
Jack
  • 15,614
  • 19
  • 67
  • 92