Find Duplicate fx_price records and Discover which record should be kept/DeletedSummaryThere should always be only one fx_price record where the fields id, table and field are the same value This is a script that can be used to determine the stored database value of the record and which fx_price record should be kept and which should be deleted if you have 2 duplicates This will only consider records that the parent is null as multiple records can exist for multiple currency type ReleaseAllInstructions//Populate the variables tbl and fld with the table and field you wish search //Replace <table> with the table //replace <field> with the field var tbl = '<table>';var fld = '<field>' var fxp = new GlideAggregate('fx_price');fxp.addEncodedQuery('table=' + tbl + '^field=' + fld + '^parent=NULL');fxp.addAggregate('COUNT');fxp.addHaving('COUNT','=','2');fxp.groupBy('id');fxp.query()while (fxp.next()){ gs.print(fxp.id + ' => ' + fxp.getAggregate('COUNT')); var dbval = new GlideAggregate(tbl); dbval.addQuery('sys_id',fxp.id.toString()); dbval.addAggregate('SUM',fld); dbval.setGroup(false); dbval.query(); while (dbval.next()) { gs.print('Stored Database Value: ' + dbval.getAggregate('SUM',fld)); var amount = parseFloat(dbval.getAggregate('SUM',fld)).toFixed(4).toString(); var rec = new GlideRecord('fx_price'); rec.addEncodedQuery('table=' + tbl + '^field=' + fld + '^id=' + fxp.id.toString()); rec.query(); rec.next(); var prev = parseFloat(rec.reference_amount).toFixed(4).toString(); var fxid = rec.sys_id.toString(); rec.next(); if (prev == parseFloat(rec.reference_amount).toFixed(4).toString()) { if (prev != amount) { gs.print('Both fx_price records do not match database value'); gs.print('sys_id: ' + fxid + ' => ' + prev); gs.print('sys_id: ' + rec.sys_id.toString() + ' => ' + rec.reference_amount); } else { gs.print('Both values are the same and match database'); gs.print('sys_id: ' + fxid + ' => ' + prev + ' KEEP'); gs.print('sys_id: ' + rec.sys_id.toString() + ' => ' + parseFloat(rec.reference_amount).toFixed(4).toString() + ' DELETE'); } } else { if (prev == amount) { gs.print('sys_id: ' + fxid + ' => ' + prev + ' KEEP'); gs.print('sys_id: ' + rec.sys_id.toString() + ' => ' + parseFloat(rec.reference_amount).toFixed(4).toString() + ' DELETE'); } else { if(parseFloat(rec.reference_amount).toFixed(4).toString() == amount) { gs.print('sys_id: ' + rec.sys_id.toString() + ' => ' + parseFloat(rec.reference_amount).toFixed(4).toString() + ' KEEP'); gs.print('sys_id: ' + fxid + ' => ' + prev + ' DELETE'); } else { gs.print('Both fx_price records do not match database value'); gs.print('sys_id: ' + fxid + ' => ' + prev); gs.print('sys_id: ' + rec.sys_id.toString() + ' => ' + parseFloat(rec.reference_amount).toFixed(4).toString()); } } } }}Related LinksThis script is limited to only search 2 values