- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2014 08:10 AM
Is there an easy way to mass update templates (sys_template). I would like to change a field in approx 700 templates and would prefer not to have to do this by hand. Looking at the value template in the GlideRecord, the template values appear to be stored as single text field making it possible to update via script but I'm hoping there is an alternate way to do this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2014 08:49 AM
The scripted approach will probably be the best approach, especially if the field name and value are the same across all of your templates. You can use a very simple script recipe to make it happen:
var gr = new GlideRecord('sys_template');
//gr.addEncodedQuery('your query here');
gr.query();
while (gr.next()) {
gr.FIELD_NAME = (gr.FIELD_NAME + '').replace('FIELDNAME=FIELDVALUE', 'FIELDNAME=NEWVALUE');
gr.update();
}
Just replace the Field Name, Field Value, and enable the addEncodedQuery line if needed (use the list view filter to obtain the encoded query).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2014 08:45 AM
Hi Bryan,
Template values are stored as an encoded query, you can do mass update using script. Please refer below script for your reference:
var grTem = new GlideRecord('sys_template');
grTem.query();
while(grTem.next())
{
grTem.template += '^active=true';
grTem.update();
}
Please mark answer as correct/helpful, if it was really helpful.
Regards,
Solutioner
Enhance Knowledge NOW@ www.solutioningnow.com
http://www.solutioningnow.com/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2014 08:49 AM
The scripted approach will probably be the best approach, especially if the field name and value are the same across all of your templates. You can use a very simple script recipe to make it happen:
var gr = new GlideRecord('sys_template');
//gr.addEncodedQuery('your query here');
gr.query();
while (gr.next()) {
gr.FIELD_NAME = (gr.FIELD_NAME + '').replace('FIELDNAME=FIELDVALUE', 'FIELDNAME=NEWVALUE');
gr.update();
}
Just replace the Field Name, Field Value, and enable the addEncodedQuery line if needed (use the list view filter to obtain the encoded query).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 12:00 PM
Can you explain this a little bit more? I am trying to update some reference fields on the template and its not working. No error, just nothing happens. The template points to reference fields on the incident table