Background Job Executing Twice for Single Request Causing Duplicate Records in Production
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi everyone,
We are facing an issue in Production where a background job is executing twice for a single Service Catalog request, resulting in duplicate records being created in my custom table sn_vul_custom_table1. In our setup, after request approval, a Run Script queues a background job which then executes a Script Include (global.myScriptIncludeProcess) to perform operations like adding URLs to Custom Table 1 and Custom Table 2.
Recently, we tested a request (RITM26009192551) to add two URLs into the sn_vul_custom_table1 table. Only one background job (SECJOB0504717) was created, but duplicate records were inserted. On checking system logs, we found that the log message “ODIN BG: execute() invoked for job SECJOB0504717” appears twice, confirming that the Script Include ran twice even though the job was scheduled only once.
However, in another request (RITM26009193805) where URLs were added to the sn_vul_custom_table2 table, the background job (SECJOB0504718) executed only once and no duplicate records were created. The logs also confirm that the Script Include executed only once in that case.
We have verified that only one job record exists for each RITM and only one workflow context is created, so the workflow is not restarting. This issue has only been observed in Production and not in lower environments (Dev/UAT/Training).
Has anyone faced a similar issue where a single background job executes multiple times in a multi-node environment or SecOps background job framework? Any guidance on why this double execution might be happening and how to prevent it would be greatly appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
ahoy @itshimesh23,
it seems to be a condition triggered twice for a single record, I would start with checking that.
Otherwise it's not much easy to help you without visibility to your instance and to those scripts...
Answers generated by GlideFather. Check for accuracy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @itshimesh23
Your global.myScriptIncludeProcess Script Include is likely executing .insert() across the payload arrays without validating if the record already exists.
- Add a get(), addQuery(), or hasNext() condition to check if the specific URL already exists in sn_vul_custom_table1 before executing the insert() method.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti