Scripts Using gr.addEncodedQuery = (...) Cause Full-Table Scans and Semaphore ExhaustionIssue Long-running background scripts executed through /sys.scripts.do can cause semaphore exhaustion, slowness, or system instability.One way this can happen is when a script incorrectly uses: gr.addEncodedQuery = ("query"); Instead of the required method call: gr.addEncodedQuery("query"); When this mistake occurs, the query filter is never applied, and the script unintentionally queries the entire table, leading to very large result sets and long-running transactions.ReleaseYokohama P7HF2aCauseThe root cause is incorrect usage of the GlideRecord.addEncodedQuery() API. ❌ Incorrect (treats method as a property) gr.addEncodedQuery = ("active=true"); This overrides the method with a string value.No filter is applied. The script queries the entire table. ✔ Correct (invokes the method properly) gr.addEncodedQuery("active=true"); This correctly applies the encoded query filter before executing gr.query(). When the method is overwritten instead of invoked: GlideRecord runs a full table scanLarge result sets cause long-running transactionsMultiple executions can stack up and lead to “stuck default semaphore” alertsSystem performance and stability are impacted See official ServiceNow documentation:🔗 https://developer.servicenow.com/dev.do#!/reference/api/zurich/server_legacy/c_GlideRecordAPI#r_Gli… Resolution1. Correct the script syntax Replace any instance of: gr.addEncodedQuery = ("encoded query"); With: gr.addEncodedQuery("encoded query"); 2. Re-run the script safely (optional) Validate in a sub-production environment before running in production. 3. Kill existing stuck transactions (if needed) If long-running scripts are still active: Navigate to: All → Active Transactions (All Nodes)→ Select the long-running /sys.scripts.do transactions→ Choose Kill Note: It may take time for the system to fully terminate them. 4. For assistance with script optimization ServiceNow Expert Services can help with safely reviewing or optimizing custom scripts:🔗 https://www.servicenow.com/services/expert-services.html