
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 11-18-2020 03:10 PM
Just wanted to save the script I just used to move records form one table to another. We had a custom incident task table before servicenow created one out of box, and wanted to move the records form our custom table to the out of box table.
This script does not convert data or transform to other fields, but if everything is equal between the 2 tables this will MOVE the data and update the numbering
var oldTable = 'u_incident_task'
var newTable = 'incident_task'
var oldTasks = new GlideRecord(oldTable);
oldTasks.query();
oldTasks.autoSysFields(false);
oldTasks.setWorkflow(false);
oldTasks.sys_class_name=newTable;
oldTasks.updateMultiple();
var highestNumber = new GlideRecord(newTable);
highestNumber.setLimit(1);
highestNumber.addQuery('number','!=','');
highestNumber.orderByDesc('number');
highestNumber.query();
highestNumber.next();
var sysNumber = new GlideRecord('sys_number_counter');
sysNumber.get('table',newTable);
sysNumber.number = (highestNumber.number.match(/\d+/g)*1);
sysNumber.update();
- 2,855 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @Jon Ulrich ,
We are trying to move records from one table to another in the scoped application. It is actually not moving the data and instead it is just copying the data and the records in the source table still exists, so it is like there are records in both tables. Can you please provide some input if you have already observed this.
Thanks.