Removal of duplicate records
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2025 02:01 AM
Hi All,
We have found some duplicate records in ast_contract table, and we need to clean up the duplicate records without deleting any records.
Could you please help us.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2025 02:15 AM
Hi mate
To clean it up, you have a few options:
-
Rename it with a suffix like
_old
-
Delete it (if appropriate)
-
Or check if you can simply mark it as inactive
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2025 03:44 AM
Hello,
Identify Duplicate Contracts in a List View or Script
Duplicates are usually defined by one or more fields (like contract_number, vendor, etc.). You can find them using:
Option A: Use a List View Grouping
Go to the ast_contract table.
Create a list view and group by the fields you think define a duplicate (e.g., contract_number, vendor).
Add a count column by adding a database view or export to Excel for filtering duplicates (count > 1).
Use Script to Tag Duplicates (Business Rule or Background Script)
You can use a background script in the Scripts - Background module to tag the duplicate records:
var seen = {}; // to track first records
var gr = new GlideRecord('ast_contract');
gr.query();
while (gr.next()) {
var key = gr.getValue('contract_number') + '-' + gr.getValue('vendor'); // Change fields as needed
if (seen[key]) {
gr.u_is_duplicate = true; // You need to create a field u_is_duplicate (true/false)
gr.update();
} else {
seen[key] = gr.sys_id;
gr.u_is_duplicate = false;
gr.update();
}
}
How to create u_is_duplicate field:
Go to Table → ast_contract
Add new field:
Column label: Is Duplicate
Column name: u_is_duplicate
Type: True/False
Thanks,
Kishore.