Set value on table from template_value field

NeilH2
Giga Guru

I have a field which is typed as a template_value on a record.

I want to take the values from the field and apply them to another record.

I've done this before and i just cannot think of the code that does it although i'm fairly certain its one - two lines at most.

Can anyone help?

1 ACCEPTED SOLUTION

Nick65
Mega Expert

Hey Neil, I actually had a similar requirement and found you can do something like this,



var gr = new GlideRecord('table_with_template_value_field');


gr.get('someSysID');


var values = ''+gr.u_set_values;         //this is your template field



  var inc = new GlideRecord('anytable');


  inc.get('someSysID');


 


          if (values){


                inc.applyEncodedQuery(values);  


                inc.update()                                         //could also be used in inc.insert()


                }



View solution in original post

7 REPLIES 7

Nick65
Mega Expert

Hey Neil, I actually had a similar requirement and found you can do something like this,



var gr = new GlideRecord('table_with_template_value_field');


gr.get('someSysID');


var values = ''+gr.u_set_values;         //this is your template field



  var inc = new GlideRecord('anytable');


  inc.get('someSysID');


 


          if (values){


                inc.applyEncodedQuery(values);  


                inc.update()                                         //could also be used in inc.insert()


                }



Thanks Nick



Thats a lot shorter and more helpful.


 

It is never too late to tell someone they're awesome. So you're it.

Thanks.

harel