Copy OOB incident data in custom u_incident_copy table including SYS_ID
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2024 03:29 AM
Hi Experts,
I have a requirement like I need to copy all incident fields data in u_incident_copy table.
Issue: I can do copying all incident data using below background script but not able to copy same sys_id.
Requirement: I need to preserve same incident record sys_id in u_incident_copy table.
Background script:
// Get all records from the incident table
var incidentGR = new GlideRecord('incident');
incidentGR.query();
// Loop through each incident record
while (incidentGR.next()) {
// Create a new record in the u_incident_copy table
var incidentCopyGR = new GlideRecord('u_incident_copy');
incidentCopyGR.initialize();
// Map each field from the incident table to the u_incident_copy table
incidentCopyGR.short_description = incidentGR.short_description;
incidentCopyGR.description = incidentGR.description;
incidentCopyGR.category = incidentGR.category;
incidentCopyGR.subcategory = incidentGR.subcategory;
incidentCopyGR.state = incidentGR.state;
incidentCopyGR.cmdb_ci = incidentGR.cmdb_ci;
incidentCopyGR.contact_type = incidentGR.contact_type;
incidentCopyGR.impact = incidentGR.impact;
incidentCopyGR.urgency = incidentGR.urgency;
incidentCopyGR.priority = incidentGR.priority;
incidentCopyGR.assignment_group = incidentGR.assignment_group;
incidentCopyGR.assigned_to = incidentGR.assigned_to;
// continue mapping the remaining fields...
// Copy the sys_id from the incident table to the u_incident_copy table
incidentCopyGR.sys_id = incidentGR.sys_id;
// Get the incident number from the incident table
var incidentNumber = '';
if (incidentGR.getValue('number'))
incidentNumber = incidentGR.getValue('number');
// Copy the incident number to the u_incident_copy table
incidentCopyGR.number = incidentNumber;
// Insert the copied data into the u_incident_copy table
var incidentCopySysID = incidentCopyGR.insert();
gs.print("Copied incident " + incidentNumber + " to u_incident_copy with sys_id: " + incidentCopySysID);
}
gs.print("Data copying completed.");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2024 06:46 AM
Hello @VeerenderG
sys_id of the record does not match with two different table's record because it will work as primary key for that record only so details can be match but the sys_id does not same for the two different tables records.
but if you are import or export the record from one Environment to other Environment at that time sys_id maybe match for the same table record like incident etc.
Second thing you are using the initialize() method so whenever its executes it will create the new sys_id for that particular record.
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Thank You