- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2019 11:19 AM
Hi there,
I am creating a fix script that look for duplicates numbers in my custome table 'x_table', for the records that share the same number, the more recent record should be renumbered to the next available number.
so far i have this script:
var dupRecords = [];
var gaDupCheck1 = new GlideAggregate('u_vendor_category');
gaDupCheck1.addQuery('active','true');
gaDupCheck1.addAggregate('COUNT','u_number');
gaDupCheck1.groupBy('u_number');
gaDupCheck1.addHaving('COUNT', '>', 1);
gaDupCheck1.query();
while (gaDupCheck1.next()) {
dupRecords.push(gaDupCheck1.u_number.toString() + '\n');
}
gs.print(dupRecords);
So it will retrun an array with the duplicates number, any help?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2019 11:31 AM
Hi,
Unless this is all purely coincidental...which I doubt, you aren't "creating" a fix script, haha, this has been posted in numerous threads, to include: https://community.servicenow.com/community?id=community_question&sys_id=d28b8761db9cdbc01dcaf3231f96... from like 5 years ago.
So this script will return an array of all the numbers that have a duplicate entry.
Not sure what else you're asking....
Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2019 11:38 AM
yes thats right this will return an array of all the numbers that have a duplicate entry. i would like to get a record with the same number and updated the recent record with another available number in the system so then it will not be longer duplicate.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2019 11:43 AM
Here's my thread:
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2019 12:10 PM
i dont relly get the following:
i runing this in a background script
function fixDuplicates(num) { // num can be replace with what?
var gr = new GlideRecord('incident');
gr.addQuery('number', num); // here as well what shall i puit in 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);
}