- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2019 12:22 AM
I want to copy a record into the same table with different sys_id. Below is the code that I've written for this. Issue is even though retrieval is successful, canvas_name and feedbacks are not getting copied somehow and new record is getting generated with blank value of canvas name and feedback. Below is the screenshot of table structure and record list.
Script :
var caller = "321926301beb3300e5a2fc88cc4bcb04";
var sysparm_canvas = 2;
var gr = new GlideRecord("x_390488_retro_app_retro_feedback");
gr.addQuery("sys_id",caller);
gr.query();
if(gr.next()){
var feedback_type = gr.feedback_type;
var feedback = gr.feedback;
var canvas_name = gr.canvas_name;
gs.info (" feedback_type : "+feedback_type); // printing the record
gs.info (" feedback : "+feedback); // printing the record
gs.info (" canvas_name : "+canvas_name); // printing the record
gr.initialize();
gr.feedback= feedback; // not working
gr.canvas_name= canvas_name; // not working
gr.feedback_type= feedback_type; // working
gr.canvas_id = sysparm_canvas; // working
gr.insert();
}
Table Structure:
View List:
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2019 04:08 AM
Can you try this ?
ar caller = "321926301beb3300e5a2fc88cc4bcb04";
var sysparm_canvas = 2;
var gr = new GlideRecord("x_390488_retro_app_retro_feedback");
gr.addQuery("sys_id",caller);
gr.query();
if(gr.next()){
//get value from gliderecord
}
var gr1 = new GlideRecord("x_390488_retro_app_retro_feedback");
gr1.initialize();
//set values
gr1.insert();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2022 02:00 AM
Short addition to the answer from Abhishek regarding using the same instance of GlideRecord. This is not working when you use a "while" loop instead of "if (gr.next(()", then you need to create a new instance of GlideRecord; e.g.
var getRec= new GlideRecord("<table x>");
getRec.addEncodedQuery= "<query to find the records they need to be copied>";
getRec.query();
while (getRec.next()){
var value1= getRec.val1;
var value2= getRec.val2;
var setRec= new GlideRecord("<table x>");
setRec.initialize();
setRec.val1= value1;
setRec.val2= value;
setRec.insert();
}