You can configure a validator customization to ensure that
entries for an attribute are in a specific format.
About this task
This task uses a Regular Expression validator to ensure that the
values entered by users for an attribute are in a specific format. In the following example, the
Product Number attribute requires that values are in the following format: four alphabetic
characters, dash, five digits, dash, one of P, Y, or Z.Note: To create a validator with a script,
see the
Wiki page.
Procedure
- Open the Attribute Customization page:
- In the Team Artifacts view of the Work Items perspective,
right-click the project area and select Open.
- Click the Process Configuration tab.
- Expand , and then click Attribute Customization.
- Select Validators, then click Add.
Enter a name that describes the customization. Select Regular
Expression from the Provider drop-down list.
- In the Configuration section, accept the default Decoration
Icon of Error. In the Message field,
enter the message that is displayed as a tooltip when a user enters
a value that does not comply with the specified format. In the Regular
Expression field, enter the expression for valid format
entries for the attribute. To ensure that your expression is correct,
try entering a string in the Try the Regular Expression
on sample text field.
- Click Attributes and Types. Select
the work item type, such as Defect or Task. Scroll to the Attributes section.
Click Add. Create a custom attribute named
Product Number of type Small String. Select
Product Number in the Validators field. Click OK.
- Click Editor Presentations. Select
the editor presentation to which you want to add a field for the new
attribute. Select the tab and then section to which you want to add
the field. For example, the Details section
on the Overview tab. With the section selected,
click Add Presentation to add the field for
the new attribute.
- Click Save to save your changes to the project
area.
When users enter values in the Product Number field that are not in the required
format, the tooltip message is displayed near the field. However, users can save work items even if
they include values that are not in the required format. To prevent users from saving such work
items, continue to the next step.
- Expand Team Configuration, then
click Operation Behavior. Click in the Everyone cell
for the Save Work Item action. In the Preconditions section,
click Add. Select the Attribute
Validation precondition.
Note: The Attribute
Validation preconditions works only with validators that have the Error Decoration
Icon.
- Click Save to save your changes
to the project area.
Results
When users attempt to save work items that have an invalid
entry in the Product Number field, the following message is displayed
in the Team Advisor view: