GlideRecord on sys_template is not working

farukhkhan
Mega Contributor

HI All,

I have written below given script:

var grTemplate=new GlideRecord('sys_template');
grTemplate.query();
gs.print(grTemplate.getRowCount());
while(grTemplate.next()){
gs.print(grTemplate.sys_id);
}

I want to print the sys_id of each record but its not getting printed...Can anyone tell me what can be  the issue here?

 

Thanks,

Faruk

1 ACCEPTED SOLUTION

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

@t_anurag is correct that with the sys_template table you have to use "_next()" and that is because there is a field named "next" on the sys_template table.  With your original script it is looking at that attribute and not going to the next record, thus _next() makes it work.

View solution in original post

3 REPLIES 3

Anurag Tripathi
Mega Patron
Mega Patron

Hi Faruk,

 

This will work

 

var grTemplate=new GlideRecord('sys_template');
grTemplate.query();
gs.print(grTemplate.getRowCount());
while(grTemplate._next()){   //changed this to _next()
gs.print(grTemplate.sys_id);
}

-Anurag

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

@t_anurag is correct that with the sys_template table you have to use "_next()" and that is because there is a field named "next" on the sys_template table.  With your original script it is looking at that attribute and not going to the next record, thus _next() makes it work.

kemmy1
Tera Guru

Thank you!  That was about 30 minutes of my life that I can never get back trying to figure this out!  🙂  Thanks so much for posting this and answering it!