How to delete duplicate records in service offering(service_offering)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 08:36 AM - edited 11-28-2024 10:02 AM
Hi Team,
i have requirement to delete duplicate records
but need to check name, parent and service classification
for eg: if i have data name as abc parent as yzi and service classificaition as business service
and if i have data name as abc parent as yzi and service classificaition as techinical service
need to return data
and if i have data name as abc parent as yzi and service classificaition as business service
and if i have data name as abc parent as yzi and service classificaition as business service
need to delete
please advice
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2024 04:46 AM
Run Fix script to delete the records
Thanks,
Raj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2024 06:02 AM
Hi @vamshi2 ,
Try the below script and it will works.
var grDel = new GlideRecord('service_offering');
grDel.addEncodedQuery('nameSAMEASname^parentSAMEASparent^service_classification=Business Service');
grDel.query();
var uniqueRecords = {};
while (grDel.next()) {
var key = grDel.name + '-' + grDel.parent + '-' + grDel.short_description;
if (uniqueRecords[key]) {
grDel.deleteRecord();
gs.info('Deleted duplicate record Sys ID: ' + grDel.sys_id);
}
else {
uniqueRecords[key] = gr.sys_id;
}
}
It is always advised to run in non prod envts first and ensure that it is recorded for roll back.
Sai Kumar P
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2024 01:51 AM
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark