belt and braces fix approach:
but below is a fix script example to fix historic tickets with duplicate numbers
//--sys_ids for duplicate numbers selected based on the latest created of the duplicates
var bUpdate = false;
bUpdate = true;
//--dupl INCIDENTS
duplIncidents(bUpdate);
//--dupl CHANGE:
duplChgRequests(bUpdate);
//--dupl ST CHANGE:
duplStChgRequests(bUpdate);
printFullList();
var bDelete = false;
//bDelete=true;
if (bDelete) {
tidyUpSubProd(bDelete);
}
function duplIncidents(bUpdate) {
var inc_sysids = 'd9f0e709db54a68074abffa9bf961xxx,8894b385db62e60074abffa9bf961xxx,cfbc2ccd4f51364057db0b318110cxxx';
var sysidsARR = inc_sysids.split(',');
for (iC = 0; iC < sysidsARR.length; iC++) {
renameDuplNumber(sysidsARR[iC].toString(), 'incident', 'd_', bUpdate);
}
//renameDuplNumber('f4e822d9db0f4f4074abffa9bf961xxx', 'incident', 'd_', bUpdate);
}
function duplChgRequests(bUpdate) {
var chg_sysids = renameDuplNumber('27e1abb41b16c41c89070e9c5e4bcxxx', 'change_request', 'd_', bUpdate);
}
function duplStChgRequests(bUpdate) {
//--dupl STDCHANGE: this record had 3 duplicates
renameDuplNumber('202340cc47410200e90d87e8dee49xxx', 'std_change_proposal', 'd_', bUpdate);
renameDuplNumber('c407515147810200e90d87e8dee49xxx', 'std_change_proposal', 'd2_', bUpdate);
renameDuplNumber('af47d04047810200e90d87e8dee49xxx', 'std_change_proposal', 'd_', bUpdate);
}
function renameDuplNumber(ticketSYSID, tableName, duplPrefix, bUpdate) {
var grDupls = new GlideRecord(tableName);
grDupls.addQuery('sys_id', ticketSYSID);
grDupls.query();
if (grDupls.next()) {
grDupls.autoSysFields(false); //--leave last updated intact
grDupls.setWorkflow(false); //--skip business rules and notifications
grDupls.setEngines(false); //--skip data policy rules
var sNum = grDupls.number;
var sNewNum = duplPrefix + sNum;
grDupls.number = sNewNum;
if (bUpdate) {
var sRes = grDupls.update();
gs.print(sRes + ' updated to ' + grDupls.number + ' [' + ticketSYSID + ']');
} else {
gs.print('set update flag to true to update --' + ticketSYSID);
}
}
}
function printFullList() {
var sysids = '227c57f81b52c41c89070e9c5e4bcxxx,27e1abb41b16c41c89070e9c5e4bcxxx,c22f9bc5db54a68074abffa9bf961xxx';
var sysidsARR = sysids.split(',');
var tableName = 'task';
for (iC = 0; iC < sysidsARR.length; iC++) {
var grDupls = new GlideRecord(tableName);
grDupls.addQuery('sys_id', sysidsARR[iC]);
grDupls.query();
if (grDupls.next()) {
gs.print(grDupls.number);
}
}
}
function tidyUpSubProd(bDelete) {
instURL = gs.getProperty('glide.servlet.uri');
if (instURL.indexOf('https://prod.service-now.com') > -1) {
gs.print('Not to be run on prod!!');
} else {
var sQuery = 'numberINCHG50003xx,INC00156zz,INC00250yy,d_INCHG50003xx,d_INC00156zz,d_INC00250yy';
var grDelRecords = new GlideRecord('task');
grDelRecords.addQuery(sQuery);
if (!bDelete) {
grDelRecords.query();
gs.print('RECORDS TO DELETE: ' + grDelRecords.getRowCount() + '-- target:6');
} else {
grDelRecords.deleteMultiple();
}
}
}
Comments
Post a Comment