Duplicate locations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2023 09:05 PM
Hello,
I have duplicates in cmn_location table and having data in all the duplicate records. I want to merge those records into one record. Can someone help me with the script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2023 09:34 PM
Hi @Sai Cerni ,
This is a very complex coding required, follow this sample script and use your location table :
https://www.servicenow.com/community/now-platform-forum/merge-duplicate-records/m-p/1069929
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2023 09:45 PM
//Query data from location 1
var gr1 = new GlideRecord ( ' table_name ' ) ;
gr1.addQuery ( 'location ' , ' location_1 ') ;
gr1.query();
// Query data from location 2
var gr2 = new GlideRecord('table_name');
gr2.addQuery('location', 'location_2');
gr2.query();
// Merge data from location 1 and location 2
while (gr1.next()) { gr2.addQuery('sys_id', gr1.sys_id);
gr2.query();
if (!gr2.next()) { gr2.initialize(); gr2.location = 'location_1_2_merged';
gr2.sys_id = gr1.sys_id;
gr2.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2023 09:45 PM
Just wondering if this script works