diff --git a/Server-Side Components/Background Scripts/Get Duplicate/README.md b/Server-Side Components/Background Scripts/Get Duplicate/README.md index 23de281b78..dac606a043 100644 --- a/Server-Side Components/Background Scripts/Get Duplicate/README.md +++ b/Server-Side Components/Background Scripts/Get Duplicate/README.md @@ -1,3 +1 @@ -Using GlideAggregate function to find out tickets (tasks) with same number. OOB there happens to be a Unique checkbox at dictionary level -and if in case not set to True it might create duplicate numbered tickets. -Script will help find, ticekts if any. +This script identifies duplicate tickets or tasks in ServiceNow when the number field is not unique. It uses GlideAggregate to group records by number, count duplicates, and optionally list affected records with their Sys IDs and short descriptions. Helps maintain data integrity and accurate reporting. diff --git a/Server-Side Components/Background Scripts/Get Duplicate/script.js b/Server-Side Components/Background Scripts/Get Duplicate/script.js index 4ebdc39422..3ca918a4ab 100644 --- a/Server-Side Components/Background Scripts/Get Duplicate/script.js +++ b/Server-Side Components/Background Scripts/Get Duplicate/script.js @@ -1,8 +1,15 @@ -var dpchk = new GlideAggregate('task'); -dpchk.groupBy('number'); -dpchk.addHaving('COUNT', '>', 1); -dpchk.query(); -while(dpchk.next()) -{ - gs.print(dpchk.number); +// Table to check (e.g., task, incident, change_request) +var tableName = "task"; + +var ga = new GlideAggregate(tableName); +ga.addAggregate("COUNT", "number"); // Count how many times each number appears +ga.groupBy("number"); // Group records by number +ga.addHaving("COUNT", ">", 1); // Only show duplicates +ga.query(); + +gs.print("=== Duplicate Ticket Numbers in " + tableName + " ==="); +while (ga.next()) { + var ticketNumber = ga.getValue("number"); + var count = ga.getAggregate("COUNT", "number"); + gs.print("Number: " + ticketNumber + " | Count: " + count); } diff --git a/Server-Side Components/Business Rules/Close State/README.md b/Server-Side Components/Business Rules/Close State/README.md new file mode 100644 index 0000000000..2dcffe73e6 --- /dev/null +++ b/Server-Side Components/Business Rules/Close State/README.md @@ -0,0 +1 @@ +To close a parent record when its children are closed in ServiceNow, create a Business Rule or Flow Designer on the child table. This rule should trigger when a child record's state changes to "closed," check if all related child records are closed, and then update the parent record's state accordingly. diff --git a/Server-Side Components/Business Rules/Close State/script.js b/Server-Side Components/Business Rules/Close State/script.js new file mode 100644 index 0000000000..0b3a941ed5 --- /dev/null +++ b/Server-Side Components/Business Rules/Close State/script.js @@ -0,0 +1,25 @@ +var pSysId = 'sys_id'; +var child= new GlideRecord('incident'); +child.addQuery('parent_incident',pSysId); + +child.query(); +var count=0; +while(child.next()){ + + if(child.state!=7) + { +count =1; + gs.print("your child incident is not there or is not yet closed"); + } + + +} + +if(count==0){ + child.parent_incident.state=7; + child.parent_incident.close_code='Duplicate'; +child.parent_incident.close_notes="done"; +child.parent_incident.update(); +gs.print("hello" + child.parent_incident.number); + +}