Copy data from table to a custom table

Shiva Kumar8
Kilo Guru

Hi community,

we are trying to copy the data from Assessment instance table to a custom table we created with similar fields,

initially we want to copy all the data from Assessment table and after that we want to create a scheduled job that runs daily and copies all the assessments that are created that day, please help me with the script that will let us copy all the data to the custom table.

1 ACCEPTED SOLUTION

Mahesh23
Mega Sage

Hi,

try below code

Note : replace incident table with assessment table and u_custom with your custom table name.

var gr = new GlideRecord('incident');
gr.query('active",'true');
if(gr.next()){

var gr1 = new GlideRecord('u_custom');
gr1.initialize();
gr1.u_name= gr.name;
gr1.u_number = gr.number;
gr1.insert();
}

 

Or create business rule on assessment table and try below code 

var gr1 = new GlideRecord('u_custom');
gr1.initialize();
gr1.u_name= current.name; // replacefield name as per your requirement
gr1.u_number = current.number;
gr1.insert();
}

.

Please mark my response as correct answer or helpful if applicable 

View solution in original post

7 REPLIES 7

Hi Ankur,

I was able to copy all the data from assessment instance table to the custom table

below is the screenshots(both screenshots are of different records) of custom table and assessment instance table, the assessment instance Questions area data needs to be copied to the custom table

and the script only copied the data but not the responses, if I click on the view responses link at the bottom the responses are not showing

This is the custom table data

find_real_file.png

 

This is Assessment instance table 

find_real_file.png

Hi Ankur,

 

Any update on this?

Thanks.

Hi,

check this link on how to copy including related list table data

Re: i want to copy the related list from a record to another record in the same table(say change)?

Related list copy

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader