Defining a Default Value or Copying a Value to a Field
You can specify a default value for a field, or you can copy the value from another field or system-defined value. Field defaults are rules that control how field values are automatically assigned. You can assign a field default by using one of the following elements: COPY, DEFAULT, and SERVERDEFAULT. You can specify these elements as child elements of the FIELD (Definition) element or the FIELD (Workflow) element.
The COPY and DEFAULT elements fill in values at the start of editing, but the SERVERDEFAULT rule fills in a value when the work item is committed to the database. This action occurs when a user saves changes to a work item, and the user cannot override the value. Such fields usually appear as read-only on the work item form. The SERVERDEFAULT rule is used for fields such as "Last Changed By" and "Last Changed On" to support secure audit trails.
In this topic
Syntax Structure for Defining Default Values
Defining a Default Value
Clearing a Field Automatically
Saving a Field Value
Specifying the Clock as a Default
Syntax Structure for Defining Default Values
You can use the COPY, DEFAULT, and SERVERDEFAULT elements to copy a value from one field to another, copy a server value into a field, or specify a default value to be defined for a field.
Note
If the work item is being changed, the COPY or DEFAULT elements rule may select either the current or previous value from the source field.
You can specify a value to copy from another field, the value of the clock, or the name of the current user. If you specify value or field for the from attribute, you must specify the value or field attribute. When a user changes or creates a work item, the COPY rule fills in a field value regardless of any value that is already in the field.
<COPY for="userGroupName" not="userGroupName" from="value | field | clock | currentuser" value="valueToCopy" field="fieldReferenceName/>
You can specify a default value for a field by using the DEFAULT rule. When a user creates or edits a work item, the DEFAULT rule fills in a value if that field is empty. You can specify a value to copy from another field, the date-time stamp that the server clock records, or the name of the current user. If a field already has a value, this rule is ignored.
<DEFAULT for="userGroupName" not="userGroupName" from="value | field | clock | currentuser" value="defaultValue" field="fieldReferenceName" />
You can specify a value to copy from the server into a field when the work item is saved. When a user changes the state of a work item, the SERVERDEFAULT rule specifies a value to be copied into the current field from a value that is derived from a server component. The DEFAULT and COPY elements fill in values when a user opens a work item to modify it, but the SERVERDEFAULT rule fills in a value when the work item is committed to the database. This action occurs when the user saves the work item. The user cannot override the value. These fields usually appear as read-only on the form. The SERVERDEFAULT rule is used for fields such as "Last Changed By" and "Last Changed On" to support secure audit trails.
<SERVERDEFAULT for="userGroupName" not="userGroupName" from="clock | currentuser" />
Each of these rule elements specifies a from="fromType" attribute that identifies the source of the value. Depending on the fromType value, additional attributes may be required. The following table describes all of the attributes that the COPY, DEFAULT, and SERVERDEFAULT rule 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 |
from |
Required. Specifies whether to copy the default value from the value attribute, the field attribute, the system clock, or the current user. If you specify value or field for the from attribute, you must specify the value or field attribute, respectively. You can specify the following values:
|
value |
Optional. Specifies the value to be copied into the field when value is specified for the from attribute. Valid values consist of a string of text that contains between 1 and 255 characters. The value to copy can be empty. |
field |
Optional. Specifies the name of the field whose value is to be copied into the field when field is specified for the from attribute. You must define this attribute if the from attribute has "field" as its value. The reference name of the field to copy. The reference name must match the reference name as defined in 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
Defining a Default Value
The following example sets P3 as the default for the Priority field.
<FIELD refname="MyCorp.Priority" name="Priority" type="String">
<HELPTEXT>Specify the severity of the problem</HELPTEXT>
<ALLOWEDVALUES>
<LISTITEM value="P1"/>
<LISTITEM value="P2"/>
<LISTITEM value="P3"/>
</ALLOWEDVALUES>
<DEFAULT from="value" value="P3"/>
</FIELD>
Back to top
Clearing a Field Automatically
In the following example, the status field is cleared.
<FIELD refname="MyCorp.Status" name="Status" type="String">
<COPY from="value" value="" />
</FIELD>
Back to top
Saving a Field Value
In the following example, the name of the user who changed a work item most recently is saved.
<FIELD refname="System.Last Changed By" name="Last Changed By" type="String">
<HELPTEXT>The name of the user who most recently modified this bug</HELPTEXT>
<VALIDUSER group="[Project]\MyProjectMembers" />
<SERVERDEFAULT from="currentuser" />
</FIELD>
Back to top
Specifying the Clock as a Default
In the following example, the value of a field uses the current date but users can change that value.
<FIELD refname="MyCorp.FoundOn" name="Found On" type="DateTime">
<HELPTEXT>Defines when a bug was found.</HELPTEXT>
<DEFAULT from="clock" />
</FIELD>
Note
For values that contain an apostrophe, such as "Won’t Fix", you must use double quotation marks in the XML,as the following example shows:
<LISTITEM value="Won’t Fix"/>
Back to top
See Also
Concepts
All FIELD XML Elements Reference