The CreatorCon Call for Content is officially open! Get started here.

Quick Way to copy a glide record and insert as new one

prashant_gadgil
Tera Contributor

Hello,

I have a a table in scoped app which has 50+ columns.

For testing pursposes, I want to develop a UI action to copy an existing row all 50+ fields, copy all butcouple of fields from existing row like address fields, phone number etc, modify only a couple of them like first name, last name and insert it into the same table again.

 

Is there a short hand way of doing a deep copy of glide record?

e.g. if possible I dont want 50+ lines of snippet below...

grnew.address1=current.address1;

grnew.address2=current.address2;

...50 times...

 

grnew.firstname = "new First Name" + randomNumber

grnew.lastname = "New last Name" + randomNumber;

grnew.insert();

 

 

 

instead I would like ideally is something like below:

grnew = current.deepcopy();

grnew.firstname = "new First Name" + randomNumber

grnew.lastname = "New last Name" + randomNumber;

grnew.insert();

 

Any suggestions for an efficient way of doing this deep copy?

 

 

1 ACCEPTED SOLUTION

puneetgoels1
Tera Guru

This should help you. you can create another glide record to insert. Let me know if you need that code as well

 

var gr = new GlideRecord('incident');
gr.addQuery('number','INCPA0013565');
gr.query();
gs.info(gr.getRowCount());

if (gr.next()) {

for(var variable in gr) {
             gs.info(variable);

            gs.info(gr.getValue(variable));
}

}

View solution in original post

2 REPLIES 2

puneetgoels1
Tera Guru

This should help you. you can create another glide record to insert. Let me know if you need that code as well

 

var gr = new GlideRecord('incident');
gr.addQuery('number','INCPA0013565');
gr.query();
gs.info(gr.getRowCount());

if (gr.next()) {

for(var variable in gr) {
             gs.info(variable);

            gs.info(gr.getValue(variable));
}

}

Jace Benson
Mega Sage

If the properties are the same you can just do a for in loop;

for (prop in current){
  grnew.setValue(prop, current.getValue(prop);
}
grnew.insert()