How to: Make a String Field Match a Pattern

You can modify a string field so that the format of the string must match a pattern you define. To do this, you export the work item type XML file and modify its content. As soon as you have modified the string field, you can import the XML file to start to use the updated work item type.

Required Permissions

To perform this procedure you must be a member of the Team Foundation Administrators group or a member of the Project Administrators group for the project. For more information, see Team Foundation Server Permissions.

To make string fields match patterns

  1. If you are modifying a work item type on a single project, run witexport to export the XML file for the work item type you want to modify. For more information, see How to: Export a Work Item Type from an Existing Project.

  2. In Visual Studio, click File, click Open, and then click File.

    This displays the Open File dialog box.

  3. Under Look in, move to the location where you exported the file.

    If you are modifying a work item type to customize a process template, move to the location where you downloaded the process template.

    Note

    If you are running Windows Vista, you might not have access rights to certain folders. If you try to export the work item type to a location where you do not have access rights, the registry virtualization technology automatically redirects the exported file and saves it to the virtual store. For more information, see https://go.microsoft.com/fwlink/?LinkId=92325 and https://go.microsoft.com/fwlink/?LinkId=92323. To avoid this redirection, you can export the file to a location where you have access rights.

  4. Select the work item type XML file that you want to update, and then click Open. When you are prompted about line endings, click No.

  5. In the <WORKITEMTYPE> section, find the <FIELDS> section of the XML file.

  6. Add the XML as shown highlighted in the following example to add a Version field that tracks the version of the product to which this work item type applies.

    <FIELDS>
    <FIELD name="Version" refname="MyCompany.MyProcess.Version" type="String">
    </FIELD>
    
  7. Add the XML as shown highlighted in the following example, to make sure that all Version values start with the letter v followed by two digits, a period, two more digits, another period, a letter, and then any character.

    Note

    For more information on match patterns, see Defining Field Rules.

    <FIELDS>
        <FIELD name="Version" refname="MyCompany.MyProcess.Version" type="String">
        <MATCH pattern="vNN.NN.AX"/>
    </FIELD>
    
  8. Find the <TabGroup> section of the XML file. Within this section, the following lines define controls. Add the XML as shown highlighted in the following example, to display the Version field on the work item form.

    <Column PercentWidth="100">
      <Control Type="FieldControl" FieldName="Microsoft.VSTS.Common.Issue" Label="Issue" LabelPosition="Left" />
      <Control Type="FieldControl" FieldName="Microsoft.VSTS.Common.ExitCriteria" Label="Exit Criteria" LabelPosition="Left" />
      <Control Type="FieldControl" FieldName="Microsoft.VSTS.Build.IntegrationBuild" Label="Integration Build" LabelPosition="Left" />
      <Control Type="FieldControl" FieldName="Microsoft.VSTS.Scheduling.TaskHierarchy" Label="Task Context" LabelPosition="Left" ReadOnly="True" />
      <Control Type="FieldControl" FieldName="MyCompany.MyProcess.Version" Label="Version" LabelPosition="Left" />
    </Column>
    
  9. On the toolbar, click Save to save changes to the XML file.

  10. Import the updated work item type.

    To import the new work item type to a single project, see How to: Import a Work Item Type to an Existing Project.

    To add the work item type to your process template, see Work Item Types.

To verify changes imported to a single project

  1. In Team Explorer, click Refresh to download the latest updates from the server.

    These updates include the changes that you just imported. Wait several seconds until the Work Items node is loaded. Nodes that are still loading are labeled working.

  2. Create a new work item using the work item type you modified. To do this, right-click the Work Items node, point to Add Work Item, and then click the work item type.

    This work item is created from the work item type that you changed and imported.

  3. Find the Version field and type different values into it to see which values are allowed. The field is highlighted when it contains an illegal value.

  4. Click Close to close the new work item. Click No when you are prompted to save the work item.

See Also

Tasks

How to: Create a Pick List

How to: Create a Dependent Pick List

How to: Set a Default Value

How to: Customize the Assigned to Field

Concepts

Using the <WHEN>, <WHENNOT>, and <WHENCHANGED> Conditions