Multiple TASKs with the same numbers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2019 08:26 AM
We have a legacy custom-built application that extends the task table. When an item in this application is created, it generates a TASK (i.e. TASK123456). With the Service Catalog generating TASKs (as expected), we noticed both the application and the Service Catalog create TASKs with the same number. They seem to not be aware of each other and take the next number available. How do we fix this?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2019 08:44 AM
Hi Michael,
Check Record numbering.
Might be the prefixes(TASK) are same for your Service Catalog requested Item Tasks and Tasks generated by your application. To avoid same numbers change the prefix of tables.
Mark If Correct/Helpful.
Regards,
Ajay

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2019 08:50 AM
You should enforce unique numbering for task records to avoid this issue in future.
https://docs.servicenow.com/bundle/london-platform-administration/page/administer/field-administration/concept/c_EnforcingUniqueNumbering.html
To fix existing duplicate task numbers, you can use below fix script. Update table number in GlideRecord to your table ( sc_task).
gatherDupes();
function gatherDupes() {
var ga = new GlideAggregate('incident');
ga.addAggregate('COUNT', 'number');
ga.addQuery('number', '!=', '');
ga.groupBy('number');
ga.addHaving('COUNT', '>', 1);
ga.query();
var dupNames = [];
gs.print('The incident table has ' + ga.getRowCount() + ' duplicates based on number field...');
while (ga.next()) {
gs.print(ga.number);
fixDuplicates(ga.number);
}
}
function fixDuplicates(num) {
var gr = new GlideRecord('incident');
gr.addQuery('number', num);
gr.orderByDesc('sys_created_on');
gr.query();
while (gr.next()) {
var nm = new NumberManager('incident');
gr.number = nm.getNextObjNumberPadded();
gr.update();
}
gs.print(gr.number);
}
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2021 10:18 AM
var curNum = current.number;
var count = new GlideAggregate('dmn_demand');
count.addQuery('number', '=', curNum);
count.addAggregate('COUNT');
count.query();
if (count.next())
var newNum = getNextObjNumberPadded();
gs.addInfoMessage("The number " + current.number + " was already used by another. The number has been changed to " + newNum);
current.number = newNum;