Configuring dynamic required attributes

You can configure a condition customization to require users to provide a value for an attribute when another attribute contains a specific value.

Before you begin

To configure dynamic required attributes, you must create a script that checks the value of an attribute to determine whether a condition is true. To use scripts to customize attributes, you must set the Enable Process Attachment Scripts property on the server Advanced Properties page. See Configuring conditions for details about setting Enable Process Attachment Scripts.

About this task

The example shown in the following task creates a condition named Finished that checks whether the work item is in the Resolved or Verified state. The Operation Behavior is then configured to require users to provide a value for the Time Spent field if the Finished condition is true.
The Finished condition uses the following script:
dojo.provide("org.example.workitems.providers.FinishedCondition");

dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;

dojo.declare("org.example.workitems.providers.FinishedCondition", null, {

    matches: function(workItem, configuration) {
        var state= workItem.getValue(WorkItemAttributes.STATE);
        console.log(typeof(state))
        return (state === "3" || state === "4"); // Resolved or Verified state
    }
});
})();

For details about writing scripts, see https://jazz.net/wiki/bin/view/Main/AttributeCustomization.

Procedure

  1. Open the Attribute Customization page:
    1. In the Team Artifacts view of the Work Items perspective, right-click the project area and select Open.
    2. Click the Process Configuration tab.
    3. Expand Project Configuration > Configuration Data > Work Items, and then click Attribute Customization.
  2. Select Conditions, then click Add. Enter a name that describes the customization. Select Script Based Condition from the Provider drop-down list.
    Screen capture of Add Configuration window with Script Based Condition selected in the Provider field.
  3. In the Configuration section, click Browse and navigate to the script that tests for the condition.
    Screen capture of Configuration section with Finished.js file in Local File Path field.
  4. 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 Required Attributes For Condition precondition.
  5. Click Add. In the Edit Required Attributes window, select the condition, in the Rule field, that you created. Then select the attribute or attributes that are required when the condition is true.
    Screen capture of Preconditions section. The Required Attributes For Condition precondition is selected. The Rule column shows the Finished condition. The Attributes column shows the Time Spent attribute.
  6. Click Save to save your changes to the project area.

Results

When users try to save Resolved or Verified work items that do not contain a value in the Time Spent field, the operation fails and a message is displayed.