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.
Service Catalog: Utilising Workflow Timers after submission of the Service Catalog Request [sc_request] and Requested Item [sc_req_item] - Support and Troubleshooting
  • >
  • Knowledge Base
  • >
  • Support and Troubleshooting (Knowledge Base)
  • >
  • Service Catalog: Utilising Workflow Timers after submission of the Service Catalog Request [sc_request] and Requested Item [sc_req_item]
KB0685140

Service Catalog: Utilising Workflow Timers after submission of the Service Catalog Request [sc_request] and Requested Item [sc_req_item]


5844 Views Last updated : Jul 24, 2025 public Copy Permalink
KB Summary by Now Assist

Issue

On a ServiceNow Instance, a user can order items from the Service Catalog and store these items in the Shopping Cart. When we submit the cart, a Request [sc_request] record is generated and each of the items that were submitted in the cart will generate into Requested Item [sc_req_item] records.  

The Requested Item[sc_req_item] will then trigger their own workflows as soon as the parent Request "Approval" field is set to "Approved"

Due to the design of the Service Catalog, the child sc_req_item record is created in the database before the parent sc_request is.

Scenario

There is a scenario where a user has set up a configuration to have the Request auto-approve, so that the Requested Item [sc_req_item] workflows trigger immediately upon submission.

In this case, this can cause an issue where "Unique Key Violation" errors can occur if the first activity in the workflow for the Requested Item [sc_req_item] is the following:

updateRequest();
function updateRequest() {
var gr = new GlideRecord("sc_request");
gr.get(current.request);
while (gr.next()) {
gr.short_description = "test";
gr.update();
}
} 

While the APIs used here are supported, executing a script above can conflict with the logic of the Service Catalog in two ways: 

  1. If this script was to execute at the time when the data of the parent Request has not been committed to the database, the GlideRecord() API will perform an INSERT into the Request [sc_request] table. This behavior can cause a unique key violation error.
  2. If the above script is run during the process of the Request [sc_request] creation, then the business rules running on the Request [sc_request] and Requested Item [sc_req_item] will run as a recursive business rule. This is the same logic as executing a "current.update(); and it is to be avoided at all cost.

Resolution

If there is business logic to update the Request [sc_request] record, then a workflow timer can be included just before the "Run Script" activity in the workflow that includes the code above. The timer is beneficial for two reasons:

  1. The timer allows the business rules to complete their execution before the Run-Script logic is then invoked.
  2. The timer allows the Run-Script and any other business rules/script-include to run asynchronously as a Scheduled Job [sys_trigger] and therefore runs as a system user, which can allow better performance.

Related Links

For more information on how a Workflow Timer can assist in script execution, please refer to KB0647534 - Workflow Engine | How does a Workflow Timer help?.


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.