Udostępnij za pośrednictwem


Specifying Field Defaults

Field defaults are rules that control the ways that field values are automatically assigned. Field defaults are expressed by using three types of elements: <DEFAULT>, <COPY>, and <SERVERDEFAULT>.

  • **<DEFAULT>   **When a user creates a new work item or edits a work item, the <DEFAULT> element fills in a field value if that field is empty. If a field already has a value, the default rule is ignored.

  • <COPY>   When a user creates a new work item or edits a work item, the <COPY> element fills in a field value regardless of any exiting value already in the field.

  • <SERVERDEFAULT>   Unlike <DEFAULT> and <COPY> that fill in values at the start of editing, the <SERVERDEFAULT> rule fills in a value when the work item is committed to the database. This occurs at save time, and the user cannot override the value. Such fields appear read-only on the form. This rule is used for fields such as "Last Changed By" and "Last Changed On" to support secure audit trails.

Each of these tags takes a from="<fromtype>" attribute that identifies the source of the value. Depending on the <fromtype>, other attributes can follow.

These are the valid from-type values:

  • value   Use the value from a specified string constant. Requires a value="abc" attribute. value is used only for <COPY> and <DEFAULT> rules.

  • field   Use the value from a specified field. Requires a field="abc" attribute. By default, if the specified 'from' field is empty, nothing is performed. field is used only for <COPY> and <DEFAULT> rules.

  • clock   Use the current date and time as the value. No additional attributes are required. Used for DateTime fields. For <COPY> and <DEFAULT> rules, this value is taken from the local computer clock time. For <SERVERDEFAULT>, the value comes from the server clock at commit time.

  • currentuser   Use the short username of the current user as the value. No additional attributes are required. Used for string fields.

Examples

In the following example, a default priority is specified:

<FIELD refname="MyCorp.Priority" name="Priority" type="String">
<HELPTEXT>Enter the severity of the problem</HELPTEXT>
    <ALLOWEDVALUES>
        <LISTITEM value="P1"/>
        <LISTITEM value="P2"/>
        <LISTITEM value="P3"/>
    </ALLOWEDVALUES>
<DEFAULT from="value" value="P3"/>
</FIELD>

In the following example, the status field is cleared:

<FIELD refname="MyCorp.Status" name="Status" type="String">
<COPY from="value" value="" />
</FIELD>

In the following example, the user name of the person who last changed a work item is saved:

<FIELD refname="System.Last Changed By" name="Last Changed By" type="String">
<HELPTEXT>The user name of the person who last modified this bug</HELPTEXT>
<VALIDUSER group="[Project]\MyProjectMembers" />
<SERVERDEFAULT from="currentuser" />
</FIELD>

In the following example, the value of a field uses the current date but can be changed by users:

<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. For example: <LISTITEM value="Won’t Fix"/>

See Also

Other Resources

Defining Field Lists