We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

How to delete duplicate records in service offering(service_offering)

vamshi2
Tera Contributor

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

 

3 REPLIES 3

RajC59005800307
Tera Guru

Run Fix script to delete the records

Kindly mark it correct and helpful if it is applicable.

Thanks,

Raj

Sai Kumar P
Tera Guru

Hi @vamshi2 ,

Try the below script and it will works.

 

SaiKumarP_0-1732888814230.png

 

 

 

 

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.

 

 
-----------------------------------------------------------------------------------------------------------------------------------
Regards
Sai Kumar P
                               If this is working for you, Accept the solution and mark it as helpful
 

Mark Manders
Giga Patron

https://www.servicenow.com/community/developer-forum/how-to-delete-duplicate-records-in-service-offe...


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark