Skip to page contentSkip to chat
ServiceNow support
    • Community
      Ask questions, give advice, and connect with fellow ServiceNow professionals.
      Developer
      Build, test, and deploy applications
      Documentation
      Find detailed information about ServiceNow products, apps, features, and releases.
      Impact
      Accelerate ROI and amplify your expertise.
      Learning
      Build skills with instructor-led and online training.
      Partner
      Grow your business with promotions, news, and marketing tools
      ServiceNow
      Learn about ServiceNow products & solutions.
      Store
      Download certified apps and integrations that complement ServiceNow.
      Support
      Manage your instances, access self-help, and get technical support.
TaskStateUtil does not evaluate "active" correctly on insert - Known Error
  • >
  • Knowledge Base
  • >
  • Known Error (Knowledge Base)
  • >
  • TaskStateUtil does not evaluate "active" correctly on insert
KB0551696

TaskStateUtil does not evaluate "active" correctly on insert


3193 Views Last updated : Jun 10, 2025 public Copy Permalink
KB Summary by Now Assist

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

The world works with ServiceNow.

Sign in for more! There's more content available only to authenticated users Sign in for more!
Did this KB article help you?
Did this KB article help you?

How would you rate your Now Support digital experience?

*

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

What can we improve? Please select all that apply.

What are we doing well? Please select all that apply.

Tell us more

*

Do you expect a response from this feedback?

  • Terms and conditions
  • Privacy statement
  • GDPR
  • Cookie policy
  • © 2025 ServiceNow. All rights reserved.