ValidateScriptForCurrentDotUpdate

  • Release version: Zurich
  • Updated July 31, 2025
  • 2 minutes to read
  • Summarize
    Summarized using AI
    This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.

    Summary of ValidateScriptForCurrentDotUpdate

    TheValidateScriptForCurrentDotUpdatevalidator identifies workflow activities containing scripts that use thecurrent.update()function. Usingcurrent.update()within workflow scripts can cause significant performance degradation and may lead to server instability or crashes due to infinite recursive loops. This validation helps ensure workflows avoid these issues by flagging such usage.

    Show full answer Show less

    Key Features

    • Risk Detection: Flags workflows with scripts calling current.update(), which can degrade performance or cause infinite loops.
    • Validation Results:
      • Valid: No use of current.update() detected.
      • Invalid: Lists the number of instances where current.update() is used.
    • Suggested Action: Remove all instances of current.update() from workflow activity scripts.
    • Publishable and Runnable: This validator can be published and executed within the ServiceNow platform.

    Why It Matters

    Workflows execute within transactions where the platform automatically manages record updates to the current object at the transaction’s end. Explicitly calling current.update() during transaction processing:

    • Triggers unnecessary database transactions, especially problematic if the record is not yet inserted.
    • May cause infinite loops when update-triggered business rules continuously re-invoke the workflow.
    • Leads to performance delays and potential instance hangs.

    Proper workflow design avoids calling current.update() and relies on the system’s transaction management to handle record persistence.

    Practical Guidance for ServiceNow Customers

    • Use this validator to scan workflows and identify scripts improperly using current.update().
    • Remove any current.update() calls from workflow scripts; instead, modify field values directly on current and let the transaction engine commit changes.
    • Understand that workflows are started by the script engine or workflow engine based on record inserts or updates, and all changes within a transaction are committed once processing completes.
    • Avoid calling current.update() within workflow scripts to maintain system stability and optimal performance.

    The ValidateScriptForCurrentDotUpdate validator finds workflow activities with scripts that use the current.update() function.

    Calling current.update() causes significant performance delays in transaction processing and might cause an instance to hang.

    Validation summary

    • Risk: At best, a workflow that uses current.update() in scripts experiences degraded performance. In the worst case, the workflow enters an infinite, recursive loop that crashes the server.
    • Severity Level: Warning
    • Valid Result: Valid
    • Valid Message: The JavaScript in this workflow has no instances of 'current.update()'.
    • Invalid Result: Invalid
    • Invalid Message: This workflow uses 'current.update()' in <count of current.update references> JavaScript statements.
    • Suggested Action: Remove current.update() from the activity scripts cited by this validator. Workflows execute within a transaction, and current is updated, or possibly inserted, at the end of the transaction, as appropriate. There is no need to explicitly update the record during the transaction.
    • Publishable: Yes
    • Runnable: Yes

    Problems with current.update() in workflow scripts

    A workflow initiates execution in one of these ways:
    • Script Engine: If a workflow is assigned to a specific table, and given a run condition, the workflow runs on INSERT.
    • Script: Any business rule, script include, background script, or client script can initiate a workflow using the workflow script include and calling startFlow().

    The workflow engine initiates a workflow based on the matched criteria of the current record being inserted. The transaction for current is managed by the script engine and not the workflow. Workflows that progress on the update() of the current record are not invoked via the workflow engine, but as a call from either a client script or business rule. In either case, the script engine is invoked, and the current record is put in memory. Edits and modifications to any current fields are made and are available to other activities and scripts that are executed in the same transaction.

    When appropriate, other engines that run in sequence with the workflow engine, such as the business rule engine or field normalization, are invoked against the same current record transaction. Any changes made to current through these scripts and activities modify the record in memory. These changing values are available for reference in any other transactions called from activities and scripts in the same INSERT transaction. When all expected changes are executed, the current record is inserted.

    When one of these scripts calls current.update() on a record that has yet to be inserted, the action forces an unnecessary and error-prone database transaction. If a record is not yet in the database, it cannot be updated. Business rules that trigger on update() on a record that is in the process of being inserted can cause a very unstable and potentially infinite looping condition.

    Troubleshooting

    This validator detects the use of current.update() in any of the editable script fields. Do not call current.update() from within a workflow script. In the event of an INSERT or UPDATE of current, the changes made to current are available to all scripts executing in the same transaction, and the script engine stores all changes in the database. Leave the update of current to the engine. Use the scripts only for setting and referencing the current field values.