709 views

Description

TaskStateUtil does not evaluate "active" correctly on insert. The business rule Task Active State Management triggers the script include TaskStateUtil, but on insert this script fails.

The Task Active State Management business rule contains:

//set record to inactive (close) if we move from an active state to an inactive state
if (!previousStateInactive && currentStateInactive && current.active) {
current.active = false;
gs.print(current.getDisplayValue() + ": State changed (" + previous.state.getDisplayValue() + "->" + current.state.getDisplayValue() + "), setting task to inactive");
}

The rule compares the previous and current state values. If the state changes from an active state to an inactive state, the active field is set to false.

Because the business rule calls this script before the task is created, the script include TaskStateUtil exits on the initialize function (line 36) when creating a new task:

initialize : function(/*GlideRecord*/ task) {
this.task = task;
if (!task || !task.isValidRecord())
return;

As a result, the value "closeStates" in business rule Task Active State Management is undefined and the script of this business rule exits on line 17:

//see if we have at least the close state attribute
if (closeStates == null)
return;

Steps to Reproduce

  1. Create a new table extension from task by navigating to System Definition -> Tables.
  2. Click New.
  3. Add a state value on that table > 10.
    1. Go to the form view of the new table.
    2. Right click on the State field.
    3. Click Show Choice List.
  4. Add a dictionary override on the task State field.
    1. Navigate to System Definition -> Dictionary.
    2. Search for "Table is Task" and "Column name = state" OR nav_to.do?uri=sys_dictionary.do?sys_id=9fe7e5519f1202008f97b89a442e706c.
    3. Click the Advanced view related link.
    4. Add close_states=12 to the Attributes field.
    5. Override attributes and give it a value of close_states=12.
  5. Create a new task on table from #1,
  6. Set the state to your new closed value (#2).
  7. Click Save.
    Active is still true.
  8. Create a new task.
  9. Click Save.
  10. Change the state value to the value in #2.
  11. Save again.
    Active is now false.

Workaround

  1. Navigate to System Definition > Script Includes.
  2. Open the TaskStateUtil script include.
  3. Change the following code in the initialize method:

if (!task || !task.isValidRecord())

To:

if ((!task || !task.isValidRecord()) && (!task.isNewRecord()))

Note: Remove updates from the sys_update_xml table for the script include to keep receiving updates from ServiceNow:  sys_update_xml_list.do?sysparm_query=name%3Dsys_script_include_96e1ade7c0a80a6d381ba0c6aeb4ad61


Related Problem: PRB587123

Seen In

Geneva Patch 7

Associated Community Threads

There is no data to report.

Article Information

Last Updated:2018-01-05 14:01:44
Published:2015-09-30