Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Duplicate locations

Sai Cerni
Tera Contributor

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.

 

 

3 REPLIES 3

Not applicable

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

 

//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();

}

}

Just wondering if this script works