0

I'm working on TFS API 2010.

I would like to get the available option list of a field to create a Combobox control. such as:

Priority --> [1,2,3,4] Severity-->['4-low','3-medium','2-height','1-Critical']

knowwebapp.com
  • 95
  • 4
  • 16

1 Answers1

0

You will need to export the WorkItemType Definition from TFS, then find the field in the xml and use the values from there. Below is a snippet of code that I used to get a list of transitions, if you think that the options might be in a Global List then you'll set the flag in the export method to true.

    public List<Transition> GetTransistions(WorkItemType workItemType)
    {
        List<Transition> currentTransistions;

        // See if this WorkItemType has already had it's transistions figured out.
        this._allTransistions.TryGetValue(workItemType, out currentTransistions);
        if (currentTransistions != null)
        {
            return currentTransistions;
        }

        // Get this worktype type as xml
        XmlDocument workItemTypeXml = workItemType.Export(false);

        // Create a dictionary to allow us to look up the "to" state using a "from" state.
        var newTransitions = new List<Transition>();

        // get the transitions node.
        XmlNodeList transitionsList = workItemTypeXml.GetElementsByTagName("TRANSITIONS");

        // As there is only one transitions item we can just get the first
        XmlNode transitions = transitionsList[0];

        // Iterate all the transitions
        foreach (XmlNode transition in transitions)
        {
            // save off the transition 
            newTransitions.Add(new Transition { From = transition.Attributes["from"].Value, To = transition.Attributes["to"].Value });
        }

        // Save off this transition so we don't do it again if it is needed.
        this._allTransistions.Add(workItemType, newTransitions);

        return newTransitions;
    }

Transition is a small class I have as below.

public class Transition
{
    #region Public Properties

    public string From { get; set; }

    public string To { get; set; }

    #endregion
}
Gordon Beeming
  • 585
  • 2
  • 11