Duplicate number created while creating record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2023 02:12 AM
Duplicate number created while creating record , even though the auto numbering feature is on
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2024 02:45 AM
Hello @harry24,
Yes, while I was facing the same issue we created a BR(business rule) where in all the duplicate number records were deleted and it used to check for unique number while creating a new record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2024 04:49 AM
can you help me with the business rule?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2024 05:21 AM - edited ‎01-03-2024 05:23 AM
Hello @harry24,
Following script worked for me:
var testGr = new GlideAggregate('u_test'); // table on which deletion is to be performed
testGr.groupBy('u_test_column'); // column which you think has duplicate values i think it would be the value column for sys_choice table
testGr.query();
var testGR1;
while (testGr.next()) {
testGR1 = new GlideRecord('u_test');
testGR1.addQuery('u_test_column', testGr.u_test_column);
testGR1.query();
testGR1.next(); // Skip the first result
while (testGR1.next()) { // delete the next one
testGR1.deleteRecord();
}
}
you can test this script by running it against incident table:
Steps to execute/test this script:
1) In incident table create 2 records with same short_description
2) Modify the code above and check whether only 1 record is remaining and 1 got deleted.
var testGr = new GlideAggregate('incident');
testGr.groupBy('short_description');
testGr.query();
var testGR1;
while (testGr.next()) {
testGR1 = new GlideRecord('incident');
testGR1.addQuery('short_description', testGr.short_description);
testGR1.query();
testGR1.next(); // Skip the first result
while (testGR1.next()) { // delete the next one
testGR1.deleteRecord();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2024 09:10 PM
Hello @harry24,
Did my below script solve your question, if not let me know so that I'll be able to help you.