Copy all fields from one table to another table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2024 11:47 PM
Hi All,
We are creating the custom backup tables to store the data.
We are creating the backup tables using script on certain conditions. What we want is to create all the available fields from source table to backup table as it is.
e.g We have incident table and based on condition we are creating the incident_backup table and in incident_backup table I want to create all the fields which are there in incident table.
How we can achieve this using script.
If field is choice field then it should copy all the choices as well in backup table.
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2024 11:57 PM
Hi @Peter Wood ,
Please refer below code it will work for you!
var incidentGr = new GlideRecord('incident');
incidentGr.addQuery('active', true);
incidentGr.query();
while(incidentGr.next()){
var backupGr = new GlideRecord('incident_backup');
backupGr.initialize();
backupGr.short_description = incidentGr.short_description;//you can use more fields here
backupGr.insert();
}
You can run this on background script or fix script
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2024 01:58 AM
Hi,
I want to create the fields. Your script will set the value to field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2024 12:13 AM
Hi @Peter Wood
Extent custom backup tables from the incident table all fields are copied from incident to backup tables.
Thanks
dgarad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2024 01:59 AM
Hi,
Extends will include the task table fields as well which I do not want on backup table.