- 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
08-29-2019 02:37 AM
Sorry I did a little more testing and my initial response was incorrect, so I have edited
If I run a glidequery for a record on sc_request and then insert I get an exact copy of the record, that seems to be logical
If you wish to insert a new record with new values maybe you need to add a new\separate glidequery, so you are not using the same object as your source data.
Perhaps you should first review and validate your business requirements, coping data in this manner rarely returns any long term value.
I'm not sure I'd recommend this as a solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2019 03:53 AM
Hi Tony,
Business requirement is, a user should be able to copy the existing feedback in other canvases as well, which means at the DB level in feedback table we should get one more entry of the feedback with different canvas Id. Here in my case, I am getting the canvasId from the user and Feedback Type from the actual record which are getting saved (please refer screenshot 2) but feedback and canvas name are not, even though the original records has these values.
But creating new instance of glide record and using that as a source solves this issue.
- 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
08-29-2019 04:21 AM
Interesting thing is below code is working i.e. when I have hardcoded those values to some random string then even with the same instance of GlideRecord values are getting inserted into the table:
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 = "random_feedback_type";
var feedback = "random_feedback";
var canvas_name = "random_canvas_name";
gr.initialize();
gr.feedback= feedback;
gr.canvas_name= canvas_name;
gr.feedback_type= feedback_type;
gr.canvas_id = sysparm_canvas;
gr.insert();
}