Using rich HTML descriptions instead of plain text

Objective

Allow rich HTML formatting in description fields of the MSF Agile process template.

Note: The MSF CMMI process does support HTML formatting by default. In order to use it you have to enable the formatting toolbar (see Step 6 below).

Work Item Customization

Step 1: Add a new HTML description field

Since the System.Description field is defined of type string as opposed to type HTML we need to create a new field:

2AddNewField

3AddNewField

Step 2: Change the work item layout

Use your own HTML field instead of System.Description

4EditLayout

Step 3: Refresh Work Item cache

Right-click "Work Items" in Team Explorer and select "Refresh".

5RefreshWIs

Step 4: Enable the formatting toolbar

Right-click on the Visual Studio toolbar, find and click "Formatting":

6EnableFormattingToolbar

A new toolbar will appear:

7FormattingToolbar

Result

Click into the description field and use the toolbar to format your input:

8UsingRichFormatting

 

Optional Step 5: Copying the old descriptions to the new HTML field

It would be a pity to loose the existing descriptions so let’s write a small utility using the Team Foundation Object model to copy the "old" descriptions to the new HTML field:

static void CopyOldDescriptions()
{
    // TODO: Change these values:
    string tfsName = "servertogo";
    string tfsProjectName = "WorkItemCustomization";
    string tfsHtmlDescriptionFieldName = "DescriptionHtml";
    string tfsWorkItemType = "Task";

    using (TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(tfsName))
    {
        WorkItemStore wit = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
        WorkItemCollection result = wit.Query(String.Format("SELECT [System.Id] FROM WorkItems WHERE [System.TeamProject] = '{0}' AND [System.WorkItemType] = '{1}'", tfsProjectName, tfsWorkItemType));
        List<WorkItem> affectedWorkItems = new List<WorkItem>();
        foreach (WorkItem wi in result)
        {
            if (wi.Description.Length > 0)
            {
                // Set new description
                string value = (string)wi[tfsHtmlDescriptionFieldName];
                if (String.IsNullOrEmpty(value))
                {
                    wi[tfsHtmlDescriptionFieldName] = wi.Description.Replace("\n", "<br>");
                }
                else
                {
                    wi[tfsHtmlDescriptionFieldName] += "<br><p>Old description:</p><p>" + wi.Description.Replace("\n", "<br>") + "</p>";
                }

                // Delete old description
                wi.Description = String.Empty;

                affectedWorkItems.Add(wi);
            }
        }

        if (affectedWorkItems.Count > 0)
        {
            wit.BatchSave(affectedWorkItems.ToArray());
            MessageBox.Show("Items updated: " + affectedWorkItems.Count);
        }
        else
        {
            MessageBox.Show("Nothing to do.");
        }
    }
}


Happy formatting. :-)



 



6 thoughts on “Using rich HTML descriptions instead of plain text”

  1. Hello and Thanks.
    in Visual Studio it works ok.

    But in Web Access there is a problem:
    in History tab, i see the HTML code itself.

    do you know what can i do?

    Thanks.

  2. How do I change the field so it automaticilly expand and get larger in the Microsoft Visual Studio 2008 Team System Web Access? It has an fixed size.

  3. I am using a template derived from CMMI. For me the Description data type is “Plain Text” and there’s no formatting toolbar. Was this changed in TFS 2010? (Which we’re not using yet.)

    What happens to the web access Search if we make this change? Presumably it won’t be able to search on this text ??

  4. John, this was not changed in TFS 2010. System.Description still a plain text field.

    The newest template, VS Scrum 1.0, is using a different field for it’s descriptions named Microsoft.VSTS.Common.DescriptionHtml.

    Your assumption is correct. Team Web Access only searched System.Description – you will not be able to seach your new custom field with the built-in search functionality by default.

  5. Thanks, Neno – it’s a shame the search is so limited.

    It would be nice if the next version of tfs could allow us to customize how the search works. (IE which columns are searched and which are returned.) I’ve downloaded an extension for TFS which allows me to search visual studio and I can define the exact query I want to use – it would be great to have something like that in web access search. It’s also annoying how the batch editing and the little context menu (create copy/related item etc.) is missing from the search. Hopefully that was added in tfs 2010.

  6. I need to bulk edit hundreds of product backlog items and the export to excel has the descripiton html field as read only… sure would be nice to have it as an editable field.
    thanks

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>