How to query the sys_template table in mass

lonesoac01
Giga Guru

Hello all,

 

     I am attempting to query the sys_template table with gliderecord and it appears that I cannot query the table to get a record set.  I CAN however, query the table for individual records with this code:

 

var template = new GlideRecord('sys_template');
template.get('675a23363b50265014266ea9e5e45a90');
gs.debug(template.getValue('template'));
var regexMatch = /assignment_group=(.*?)\^/.exec(template.getValue('template'));
if (regexMatch && regexMatch[1]){
         gs.debug(regexMatch[1]);
} else {
         gs.debug('No assignment group value.');
}

lonesoac01_0-1742998099763.png

 

What am I missing here?

1 ACCEPTED SOLUTION

EnriT
Tera Expert

Heya,

This is due to sys_template table having a field called "next", and I am assuming you are trying to use something in the vein of "template.next()" to query through records.

EnriT_0-1743082129496.png

As a workaround you can try using "._next()":

var grST = new GlideRecord("sys_template");
grST.addEncodedQuery('active=true');
grST.setLimit(5);
grST.query();
while (grST._next()){
    gs.info(grST.template.toString());
}

 It works for me [Washington DC Patch 10 hotfix 2].
Edit: Found the relevant dev docs as well: 
https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server_legacy/c_GlideRecordAPI#...

View solution in original post

1 REPLY 1

EnriT
Tera Expert

Heya,

This is due to sys_template table having a field called "next", and I am assuming you are trying to use something in the vein of "template.next()" to query through records.

EnriT_0-1743082129496.png

As a workaround you can try using "._next()":

var grST = new GlideRecord("sys_template");
grST.addEncodedQuery('active=true');
grST.setLimit(5);
grST.query();
while (grST._next()){
    gs.info(grST.template.toString());
}

 It works for me [Washington DC Patch 10 hotfix 2].
Edit: Found the relevant dev docs as well: 
https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server_legacy/c_GlideRecordAPI#...