How do you use GlideRecord to query records in ServiceNow?

TarunNagar
Tera Contributor

How can you use GlideRecord in ServiceNow to query records from a table? Explain its basic syntax, key methods like addQuery(), addEncodedQuery(), and next(), and provide an example of retrieving specific records based on conditions. How does GlideRecord differ from standard SQL queries in databases?

1 ACCEPTED SOLUTION

AndersBGS
Tera Patron
Tera Patron

Hi @TarunNagar ,

 

Have you looked at the documentation for the functions? This is quite well explained.

 

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

View solution in original post

5 REPLIES 5

YashSmith
Kilo Contributor

In ServiceNow, GlideRecord is used to query records from tables. Here’s how you can use it:

var gr = new GlideRecord('incident');  
gr.addQuery('priority', '1');  
gr.query();  

while (gr.next()) {  
    gs.info(gr.number);  
}

This retrieves all high-priority incidents. Dev Technosys provides expert Hire developers in USA for seamless implementations.