The TaskStateUtil API is in the task state management utility script include and is used for working with task-type table state attributes.

This API is primarily used by the Task Active State Management business rule to set the active field based on state changes. Configurations are defined in the task.state dictionary element, usually using dictionary overrides since state values vary by table.

The TaskStateUtil API can be called by any server script to determine inactive states, default work, or default close states for a table.

The required attributes are defined on the planned_task table so all planned task types are supported. We will eventually add the attributes to other task types and eventually the base task table. You are free to do this if you want to leverage this feature now.

These attributes can be defined on the task.state dictionary element or a dictionary override for extended task tables.
Table 1. Related Attributes
Attribute Definition
close_states Semicolon delimited list of state values that are inactive, used to identify whether the task should be set to active or inactive. This is a required attribute to use the TaskStateUtil functionality.
default_close_state Optional attribute to define the state value of the default close state if you want to define business rules that automatically close a task. Defaults to 3, typically Closed Complete if attribute is not defined.
default_work_state Optional attribute to define the state value of the default working state if you want to define business rules that automatically set a task for working. Defaults to 2, typically Work in Progress if the attribute is not defined.

TaskStateUtil - ATTR_DEFAULT_WORK

The name of the attribute that identifies default work state.

Table 2. Field
Name Type Description
ATTR_DEFAULT_WORK String Identifies default work state. Value: default_work_state

TaskStateUtil - ATTR_DEFAULT_CLOSE

The name of the attribute that identifies the default close state.

Table 3. Field
Name Type Description
ATTR_DEFAULT_CLOSE String Identifies the default close state. Value: default_close_state

TaskStateUtil - ATTR_INACTIVE_STATES

The name of the attribute that identifies inactive states.

Table 4. Field
Name Type Description
ATTR_INACTIVE_STATES String Identifies inactive states. Value: close_states

TaskStateUtil - getDefaultCloseState

Returns the value for the default closed state.

The default closed state value is 3 if the default_close_state attribute has not been specified.

Table 5. Parameters
Name Type Description
None
Table 6. Returns
Type Description
Number State value representing the closed state.

Example

var stateUtil = new TaskStateUtil(current);
//get the close state
var defaultCloseState =  stateUtil.getDefaultCloseState();
current.state = defaultCloseState;

TaskStateUtil - getDefaultWorkState()

Returns the value for the default work state.

The default work state value is 2 if the default_work_state attribute has not been specified.

Table 7. Parameters
Name Type Description
None
Table 8. Returns
Type Description
Number The state value representing the working state.

Example

var stateUtil = new TaskStateUtil(current);
//get the work state
var defaultWorkState =  stateUtil.getDefaultWorkState();
current.state = defaultWorkState;

TaskStateUtil - getInactiveStates

Returns a list of the inactive state values.

Table 9. Parameters
Name Type Description
None
Table 10. Returns
Type Description
Array Array of state values that are inactive.

Example

var stateUtil = new TaskStateUtil(current);
//get the inactive state values
var inactiveStates = stateUtil.getInactiveStates();

TaskStateUtil - isStateInactive(String state)

Returns the active status of the specified state.

Table 11. Parameters
Name Type Description
state String The state value to check.
Table 12. Returns
Type Description
Boolean True if the state is inactive.

Example

var stateUtil = new TaskStateUtil(current);
var previousStateInactive = stateUtil.isStateInactive(previous.state);
var currentStateInactive = stateUtil.isStateInactive(current.state);

TaskStateUtil - runMarkClosed

Decides whether the mark closed business rule should be run or not.

Table 13. Parameters
Name Type Description
None
Table 14. Returns
Type Description
Boolean Whether the business rule should be allowed to run or not.

TaskStateUtil - runTaskCloser

Decides whether the task closer business rule should be run or not.

Table 15. Parameters
Name Type Description
None
Table 16. Returns
Type Description
Boolean Determines whether the business rule should be allowed to run or not.

TaskStateUtil - runTaskReopener

Decides whether the task reopener business rule should be run or not.

Table 17. Parameters
Name Type Description
None
Table 18. Returns
Type Description
Boolean Whether the business rule should be allowed to run or not.

TaskStateUtil - setDefaultWorkState(String defaultWorkState)

Enables the user to specify their own default work state.

Table 19. Parameters
Name Type Description
defaultWorkState String The value to use for the default work state.
Table 20. Returns
Type Description
TaskStateUtil A self-reference to allow for method chaining.

TaskStateUtil - SYSTEM_DEFAULT_CLOSE

The value of the default close state is Closed Complete on the Task table.

Table 21. Field
Name Type Description
SYSTEM_DEFAULT_CLOSE Integer Value of the default close state is Closed Complete on the Task table. Value: 3

TaskStateUtil - SYSTEM_DEFAULT_WORK

The value of the default work state is Work in progress on the Task table.

Table 22. Field
Name Type Description
SYSTEM_DEFAULT_WORK Integer Value of the default work state is Work in progress on the Task table. Value: 2

TaskStateUtil - SYSTEM_INACTIVE_STATES

The values of the default inactive states: Closed Complete, Closed Incomplete, Closed Skipped on the Task table.

Table 23. Field
Name Type Description
SYSTEM_INACTIVE_STATES Integer array Values of the default inactive states: Closed Complete, Closed Incomplete, Closed Skipped on the Task table. Value: 3, 4, 7

TaskStateUtil - TaskStateUtil(GlideRecord task)

Creates a TaskStateUtil object.

Table 24. Parameters
Name Type Description
task GlideRecord This must be a GlideRecord from a task table.

Example

var stateUtil = new TaskStateUtil(current);