Click here to Skip to main content
Click here to Skip to main content

TFS Auto Complete Fields

, 4 Jul 2013
Rate this:
Please Sign up or sign in to vote.
TFS auto complete fields.

In TFS you are able to customise your process template and one of the rules you can add to a field is a SuggestedValues rule, with this you can specify many single items for suggestions or/and get the suggestion items from a global list. This works great for if you have a set list of suggestions, but what if you want to pull your suggestion list based off data in TFS.

Assumptions

Reading this we are assuming that you have a understanding of the basics of customising a process template.

Create the Magic

Add a field

Add a new field to any work item called The Auto Completing Field. Make it’s reference name be Fields.The.Auto.Completing.Field. Leave the type as string and import the work item definition into TFS.

Create a Team Query

Browse to any of the interfaces where you can create a flat query. Start a new Query,

image

And for this example create your query as below.

image

For Column options select just the “The Auto Completing Field” field, and in the sort columns select the same column. Save that query in the root of Shared queries.

Creating the server plugin

The plugin you will create is very simple and you will be able to use the source attached directly. Basically what you are going to do is whenever the configured fields are changed then you will call the query mapped to that field and update a global list which you will add as a suggested list for your field after the global list is created.

Code

The code that does the logic magic is below and all the classes being called are in the source download

Uri requestUri = GetTFSUri(requestContext);

foreach (StringField field in workItemChangedEvent.ChangedFields.StringFields)
{
    if (DoesFieldNameExistsInConfiguredFields(configuredFreeTextFields, field.ReferenceName))
    {
        IGlobalList globalList = GlobalListFactory.GetGlobalList(requestUri, 
          _configuredFreeTextAutoCompleteGobalListPrefix + 
          field.ReferenceName.Replace(".", "_"));
        globalList.ClearList();
        IQueryRunner queryRunner = 
          QueryRunnerFactory.CreateInstance(requestUri, workItemChangedEvent.PortfolioProject);

        WorkItemCollection workItemsFromQuery = 
          queryRunner.ExecuteSavedQuery(configuredFreeTextFields[field.ReferenceName]);
        foreach (WorkItem wi in workItemsFromQuery)
        {
            if (wi.Fields.Contains(workItemsFromQuery.DisplayFields[0].Name))
            {
                globalList.AddToListDistinct(
                  wi.Fields[workItemsFromQuery.DisplayFields[0].Name].Value.ToString());
            }
        }
        globalList.SaveChanges(true);
    }
}

The bits of code around the above code load configured fields from the app settings. A default example of what the config would look like for the field created in this article is below.

<add key="AutoCompleteSettings.AppSettingsPrefix" value="AutoComplete." />
<add key="AutoCompleteSettings.GlobalListPrefix" value="AutoComplete_" />

<add key="AutoComplete.Fields.The.Auto.Completing.Field" 
  value="<Your team name>/Shared Queries/The Query we just created" />

Final Touches

The server plugin should create the global list for you if it doesn’t exist, so if you go into TFS and alter the “The Auto Completing Field” then the global list for the field will be created, alternatively if you are using the default configuration you can import a global list upfront called AutoComplete_Fields_The_Auto_Completing_Field.

Basically after the global list is in TFS (no matter which method you use to get it there), you need to go back to your work item definition and add the SuggestedValues rule that uses the global list created as it values.

Publish the server plugin and import the changes made to the work item definition and we’re done =)

Enjoy

This plugin allows you to give users the flexibility to use free text fields and by making a auto complete type experience helps a bit to not have multiple values for the same thing that will later make accurate reporting slightly tougher.

Source

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Gordon W Beeming
Software Developer Derivco
South Africa South Africa
Developer who loves pushing the limits and playing with amazing @Microsoft Tech, #TFS, ALM Rangers.
 
http://31og.com
Follow on   Twitter

Comments and Discussions

 
GeneralMy vote of 5 Pinmemberjohannesnestler14-Jan-14 3:26 
GeneralRe: My vote of 5 PinmemberGordon W Beeming14-Jan-14 3:31 
Questionreply PinmemberMember 1016024518-Jul-13 8:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 4 Jul 2013
Article Copyright 2013 by Gordon W Beeming
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid