Set Conditions on a Work Item Field

You can restrict changes from being made to a field by specifying a qualifying rule, such as the CANNOTLOSEVALUE, EMPTY, FROZEN, NOTSAMEAS, READONLY, and REQUIRED elements. For example, you can use the NOTSAMEAS rule to prevent two fields from being assigned the same value or being cleared at the same time. In addition, you can use that rule to prevent the "code reviewer" field from being assigned the same value as the "assigned to" field.

You can specify these rules as child elements of the FIELD (Definition), FIELD (Workflow), or FIELD (Global workflow) elements. You can apply or ignore these rules based on who is modifying the work item by specifying a user or group for the for or not attributes, respectively.

Syntax Structure of Rule Elements for Field Values

  • You can specify the CANNOTLOSEVALUE rule to prevent a field from being cleared after a value has been specified. If you apply this rule to a field, that field must always contain a non-NULL value after a user sets the field to any value.

    <CANNOTLOSEVALUE for="userGroupName" not="userGroupName" />
    
  • You specify the EMPTY rule to clear a field of any value that it contains. This rule also makes a field read-only, and you should not use it with the READONLY rule. The field value is cleared when you save the work item, and you cannot specify any value. You primarily use this rule during state transition to clear fields that apply to the state to which the work item is transitioning.

    <EMPTY for="userGroupName"not="userGroupName" />
    
  • You specify the FROZEN rule to prevent a user from changing the field to a non-NULL value after saving the work item. As soon as a field has a value defined in the database, the value can no longer be modified.

    <FROZEN for="userGroupName" not="userGroupName" />
    
  • You specify the NOTSAMEAS rule to prevent a field from being assigned the same value as another field. The field attribute must be a valid reference name of a field.

    <NOTSAMEAS for="userGroupName" not="userGroupName" field="fieldReferenceName"/>
    

    For example, the following excerpt prevents a field from having the same value as the MyCorp.Reviewer field:

    <NOTSAMEAS field="MyCorp.Reviewer" />
    

    Use this rule for fields that are of a similar type. You cannot use it for PlainText or HTML fields.

  • You specify the READONLY rule to prevent changes to the value of a field.

    Do not use this element together with the EMPTY element because EMPTY also makes a field read-only. If you use both elements together, you might produce inconsistent results.

    <READONLY for="userGroupName" not="userGroupName" />
    
  • You specify the REQUIRED rule to require that a user must specify a value for the field. Required fields cannot be empty. Users cannot save a work item until they have defined all required fields.

    <REQUIRED for="userGroupName" not="userGroupName" />
    

Back to top

Attributes

You can restrict to whom the qualifying rules apply. The following table describes the attributes that these elements reference:

Attribute

Description

for

Optional. Specifies the name of a user or group in Team Foundation to whom the rule applies. Valid names consist of a string of text that contains between 1 and 255 characters.

Pattern value: ^[^\\]+\\[^\\]+$

Pattern value example: Domain\UserID

not

Optional. Specifies the name of a user or group in Team Foundation to whom the rule does not apply. Valid names consist of a string of text that contains between 1 and 255 characters.

Pattern value: ^[^\\]+\\[^\\]+$

Pattern value example: Domain\UserID

field

Required for NOTSAMEAS element. Specifies the reference name of the field whose value the current field is not allowed to contain.

The reference name must match the reference name that is defined by the FIELD (Definition) element. For more information, see FIELD (Definition) Element.

Pattern value: ^[a-zA-Z_][a-zA-Z0-9_]*(\.[a-zA-Z0-9_]+)+$

Pattern value example: Company.Division.IssueType

Back to top

See Also

Concepts

All FIELD XML Elements Reference

Use Tokens to Reference Users and Groups

Other Resources

Manage Permission to Create or Modify Work Items

Working with Field Rules

Define Work Item Fields