Copy variables from one scoped app table to other

anirban300
Kilo Guru

Hello Everyone,

 

I am facing one issue where I have two tables "finance" and "masterdata". When a finance ticket is created from a record producer then a masterdata ticket should be created and the variables (from 'question_answer' table) from the finance tickets should be copied to the masterdata table. I have written the below code, where the records are created in the question_answer table but I am not able to fetch the sys_id of the question, instead getting the backend name in the variable 'prop'. Can someone tell me how can I get the sys id of the question? or a different approach.

 

Code:

var order = 100;
var r2r = new GlideRecord('x_hclan_gbs_financ_r2r_request');
r2r.addQuery('sys_id', current.sys_id);
r2r.query();
while (r2r.next()) {
for (var prop in r2r.variables) {
if (r2r.variables[prop] != '') {
var gr = new GlideRecord('question_answer');

gr.value = r2r.variables[prop];
gr.table_sys_id = database.sys_id;
gr.table_name = 'x_hclan_mdm_request';
gr.question = prop; //this is getting the backend name of the field and not the sys id
gr.order = order;
order++;
gr.insert();
}
}
}

 

Note: 'database.sys_id' is getting the sys_id of the masterdata ticket created.

 

 

2 REPLIES 2

DrewW
Mega Sage
Mega Sage

If all you are trying to do is create a copy of the vars on to the masterdata record then just do something like this to copy all of the auestion_answer records to the masterdata record.

var gr = new GlideRecord('question_answer');
gr.addQuery("table_sys_id", current.getValue("sys_id"));
gr.query();
while(gr.next()){
   gr.setNewGuid();
   gr.setValue("table_sys_id", current.sys_id);
   gr.setValue("table_name", "x_hclan_mdm_request");
   gr.insert();
}

 

Hello Drew,

 

Thank you for your reply. I tried but the below api/function is not allowed in scoped app.

gr.setNewGuid();

 

 Regards

Anirban