How to confirm all Tasks associated with a new Request/RequestItem have been created
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I am using the ServiceNow api to trigger a service catalog item that generates a ServiceNow Request. I then immediately add several comments and work notes to the ServiceNow Tasks that are created for the Request. So essentially ServiceNow creates the Request, RequestItem, and several Tasks when the service catalog item is triggered. Once I have the request number, I query the sc_task table. What I am noticing is that sometimes the results of the sc_task query to find the Tasks is not complete, as in the sc_task query occurs before ServiceNow has created the Tasks. If there was only a single task, no big deal, I could delay the query until 1 task is found. However, in my case, there could be a variable number of Tasks that may be created. What api call can I make that will confirm that all the ServiceNow Request and associated RequestItem and Tasks have been created so I can query the sc_task table, and know that I have all the tasks? Thanks for any help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @BJM ,
This is a common challenge when using the ServiceNow API because catalog item fulfillment is asynchronous—the Request (sc_request), Request Item (sc_req_item), and associated Tasks (sc_task) are created by workflows after the initial API call completes.
Why Your Query Returns Incomplete Tasks
- When you submit the catalog item via the API (/api/sn_sc/servicecatalog/items/...), ServiceNow only guarantees the Request and Request Item records exist immediately.
- Task creation depends on:
- Workflow execution (Catalog Item Flow or Legacy Workflow).
- Approvals or conditions in the flow.
- There is no single API call that confirms all tasks are created because fulfillment is asynchronous.
Best Practices to Ensure All Tasks Are Ready
1. Poll for Workflow Completion
- Use the Flow Context or Workflow Context tables:
- flow_context (for Flow Designer)
- wf_context (for legacy workflows)
- Check state = complete for the context linked to your Request Item.
- Once the context is complete, all tasks should be created.
2. Use the Request State
- Query sc_req_item for stage or request_state:
- stage = request_approved or request_state = closed_complete indicates fulfillment is done.
- However, this may be too late if you only need tasks created (not completed).
3. Poll sc_task with Expected Count
- If you know the catalog item creates N tasks (or can calculate based on variables):
- Poll sc_task where request_item = <RITM sys_id> until count matches expected.
- If the number of tasks is dynamic, this is less reliable.
4. Use Event or Script Action
- Configure a Business Rule or Flow Action to send a signal (e.g., custom event or webhook) when all tasks are created.
- Your integration can wait for that event instead of polling.
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
Thanks, GP
