- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
How to write the script to inactive the duplicate records on risk assessment table? Due to the accidental import of risk assessment data from UAT to PROD the duplicates found on production env. where number is the unique field on the risk assessment table. I want the make the original one as true and duplicate to be false. Could anyone suggest script to fix the duplicates without impacting other original records?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
@Nithya Devi , Try this script and tell me if this works.
var ga = new GlideAggregate('risk_assessment');
ga.addAggregate('COUNT', 'number');
ga.groupBy('number');
ga.addHaving('COUNT', '>', 1); // only get duplicates
ga.query();
while (ga.next()) {
var dupNumber = ga.getValue('number');
var gr = new GlideRecord('risk_assessment');
gr.addQuery('number', dupNumber);
gr.orderBy('sys_created_on'); // oldest (original) will come first
gr.query();
var isFirst = true;
while (gr.next()) {
if (isFirst) {
// Keep the first/original active
gr.active = true;
gr.update();
isFirst = false;
} else {
// Mark duplicates inactive
gr.active = false;
gr.update();
}
}
}
gs.print("Duplicate cleanup complete");
Hope it helps!
Shashank Jain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hi Bhuvan,
I suggest making them inactive. Not to delete. Because if the delete the records it will delete the associated child records which will impact the original record.
Regards,
Nithya.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Yes, you can query and get the row count and update the records and set it to inactive using the background scripts I provided.
If this helped to answer your query, please mark the posts helpful & accept the solution.
Thanks,
Bhuvan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Did you get a chance to review this ?
If my response helped to answer your query, please mark it helpful & accept the solution.
Thanks,
Bhuvan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hi Bhuvan,
Thanks for the immediate response.
I will review on this and update you asap.
Regards,
Nithya.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
You can simulate the scenario in PDI and try it. Once you test and it works fine, please mark the posts helpful and accept the solution.
If you need more help or something is not working, please share the details and can help to resolve it.
Thanks,
Bhuvan