Duplicate Order Line Items Issue ProblemDuplicate Order Line Items (ORDLs) are being created. Release All Cause Out of the box, ServiceNow does not enforce uniqueness on the number field. This means the database will allow two or more records with identical numbers unless you enforce constraints. Common Causes A) Double inserts caused by UI actions Multiple rapid clicks on Submit or SaveBrowser automation tools triggering actions twiceLatency causing resubmission when a user thinks submitting failed B) Business Rule creating an unintended second insert Example: current.insert(); // inside a before/after insert BR → creates duplicates C) Scripted inserts using workflows, script includes, or integrations Any logic that inserts a Task record without proper guards can generate duplicates. D) Clone or data import inconsistencies If a cloned target already contains a number sequence ahead of the source, duplicates may arise after clone/import. E) Autonumbering collisions under heavy load Two inserts occurring simultaneously may generate the same number before either commit completes. Resolution A) Preferred Method: Before Insert Business Rule This is the method recommended in official documentation. Create a Before Insert Business Rule on Affected table (set Apply to extended tables = true so child tables inherit it): (function executeRule(current, previous /* null when async */) { var num = current.number + ''; if (!num) return; var rec = new GlideRecord(current.getRecordClassName()); rec.addQuery('number', num); rec.setLimit(1); rec.query(); if (rec.next()) { // Number already exists – assign next available var newNum = getNextObjNumberPadded(); // system function gs.addInfoMessage( "Duplicate number detected. Changing '" + num + "' to '" + newNum + "'." ); current.number = newNum; } })(current, previous); Why this helps Prevents duplicates before the record is savedRequires no database schema changesAutomatically applies to parent and all child tables When to choose this ✔ Mixed workloads ✔ High insert volume ✔ When graceful recovery is preferred over hard errors B) Alternative Method: Unique Index on number You can enforce uniqueness at the database level: System Definition → Tables → Columns → number → Unique = trueOr create a custom index under Database Indexes Pros Hard guarantee of uniquenessEnforced at database level Cons Insert attempts fail with an errorAll existing duplicates must be resolved firstMay break integrations or scripts with incorrect numbering logic