- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2017 08:23 AM
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?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2017 11:24 AM
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()
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2017 08:56 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2017 12:51 AM
Hi Mike
The field i'm template_value field i'm updating from is in a custom table, and that script requires the template "name" from the sys_template table
Regards
Neil Holden

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2017 08:58 AM
Hello Neil,
You need to create an AFTER business rule and update the target table field value as
var field = current.PASS REFERENCE FIELD NAME HERE.getRefRecord();
field.PASS TARGET FIELD NAME HERE = 'test';
field.update();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2017 01:32 AM
So a friend of mine came up with the below code to split the string and apply each value individually.
var gr = new GlideRecord("custom_template_table");
gr.addQuery("sys_id","2ff41bd1db8d8300fe71f3571d961997");
gr.query();
gr.next();
var test = gr.u_set_field_values;
var firstSplit = test.split("^"); //split by the caret icon
gs.log('Query String ' + firstSplit );
//loop through each split value and apply them to the record - ignore the EQ
for(var i = 0; i < firstSplit.length; i++){
if(firstSplit[i] != "EQ"){
var secondSplit = firstSplit[i].split("=");
gs.print(secondSplit[0] + " - " + secondSplit[1]);
inc.setValue(secondSplit[0],secondSplit[1]);
} else {
continue;
}
}
inc.update();
}