Copy all fields from one table to another table

Peter Wood
Kilo Guru

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. 

5 REPLIES 5

Community Alums
Not applicable

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

Hi,

I want to create the fields. Your script will set the value to field.

dgarad
Giga Sage

Hi @Peter Wood 

 

Extent custom backup tables from the incident table all fields are copied from incident to backup tables.

If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

Hi,

Extends will include the task table fields as well which I do not want on backup table.