Onbefore script to remove duplicates from import table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2018 03:52 PM
I have an jdbc connection that pulls in about 8000 records, I want to process all that are not duplicates.
I have a serial number field, I would like to not even write the duplicated to my import set table. Is this possible in an onbefore script?
Thanks,
Jack
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2018 04:25 PM
Hello,
For your import set table write a business rule that prevent duplicates such:
When = before
insert = true
var existing = new GlideRecord("Your_Import_Set_table_name");
existing.addQuery("serial_number", current.serial_number); //Change with your serial number field name
existing.setLimit(1);
existing.query();
if (existing.getRowCount() > 0) {
gs.log("Aborting insertion of serial number: " + current.serial_number + " + " already exists");
current.setAbortAction(true);
return;
}
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2018 05:06 PM
Thank you for the reply. So I tweaked the code but it just seems to INSERT and ignore it, even though I set it as a before insert rule:
(function executeRule(current, previous /*null when async*/) {
var existing = new GlideRecord("u_sccm_pc_by_build_collections");
existing.addQuery("u_biosserialnumber", current.u_biosserialnumber); //Change with your serial number field name
existing.setLimit(1);
existing.query();
if (existing.getRowCount() > 0) {
gs.log("Aborting insertion of serial number: " + current.u_biosserialnumber + 'already exists');
current.setAbortAction(true);
return;
}
}
)(current, previous);
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2018 05:12 PM
I also should say, I would prefer neither the original or the duplicate be kept in my import table, I would want to hand those elsewhere.
Jack
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2018 09:35 PM