logo

NJP

UI Choice List Action for Templates

Import · Feb 06, 2013 · article

Let's say you want to be on a list of records and apply a template to the selected records on a list.Here's a UI Action List script I wrote:

function applyTemplate() { var counter = 0; var sysparm_query = g_list.getChecked(); var tempGR = new GlideRecord('sys_template'); tempGR.addQuery('name', 'Reset Password'); tempGR.query(); if (tempGR.next()) { var tblGR = new GlideRecord(tempGR.table); tblGR.addQuery('sys_id', 'IN', sysparm_query); tblGR.query(); while (tblGR.next()) { counter++; var queryStr = tempGR.template.toString(); queryStr = queryStr.split(''); if (queryStr != 'EQ') { for (i = 0; i < queryStr.length; i++) { tblGR[queryStr.split("=")[0]] = queryStr.split("=")[1]; tblGR.update(); } } } } alert(counter + " records updated"); location.reload();}

View original source

https://www.servicenow.com/community/in-other-news/ui-choice-list-action-for-templates/ba-p/2276568