Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Is there any way to copy the variables in a variable editor of a record to another new record?

Arsh1
Tera Contributor

So I am trying to create a copy of a record by clicking on a UI Action. Now the problem is I don't know that how I can copy the Variable editor data from that request to the copied request.

Any help would be appreciated 🙂

 

1 ACCEPTED SOLUTION

Hi,

this worked well for me

please enhance it further

var gr = new GlideRecord('incident');
gr.get('4dcd5214070b20102011ff208c1ed020'); // older record with variables

// create new record

var rec = new GlideRecord('incident');
rec.initialize();
rec.insert();

// then iterate for question_answer and insert the variable

var question = new GlideRecord('question_answer');
question.addQuery('table_sys_id', gr.sys_id);
question.query();
while(question.next()){

var att = new GlideRecord('question_answer');
att.initialize();
att.table_sys_id = rec.sys_id;
att.table_name = question.table_name;
att.question = question.question;
att.order = question.order;
att.value = question.value;
att.insert();
}

gs.info(rec.number);

Regards
Ankur

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

View solution in original post

14 REPLIES 14

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

it would be like this

var rec = new GlideRecord('table');

rec.initialize();

var variables = current.variables.getElements();

for (var i=0;i<variables.length;i++) {

var question = variables[i].getQuestion();

var name = question.getQuestion();
var value = question.getDisplayValue();
rec.variables[name] = value;

}

rec.insert();

sharing blog for help

Copy variables from one record to another

Regards
Ankur

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

I don't think that its going to work in a UI Action

Hi,

why not?

you can use current object in UI Action which is server side

Regards
Ankur

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

can you provide a live example as im unable to do so from a UI Action. It would really help me 🙂