GlideRecord is the server-side scripting class you use in ServiceNow to read, create, update, and delete records in a table, and the official reference for it lives in the ServiceNow developer documentation, usually under the server-side scripting or API reference section. Most people get one thing wrong: they search the general product docs and find only overview pages. The full method list, with syntax and examples, sits in the developer portal’s API reference, so that is where you should start.
What Is a GlideRecord?
A GlideRecord is an object that represents a single row of a table while you work with it, and it also acts as a cursor that walks through a set of rows you have queried. You create one by naming the table you want, then you add filters, run the query, and loop through the results. It is the standard way server scripts, business rules, and script includes touch data in ServiceNow, and it is the tool you reach for whenever a UI action or a workflow needs to read or change records behind the scenes.
Where in the Docs Do You Find It?
Go to the ServiceNow developer site and open the API reference for server-side scripting. GlideRecord has its own page there, with a table of every method, each one linked to its own detail page. The general product documentation site has a shorter scripting section that explains concepts and points you toward the API reference, so it is a good place for the big picture but not for exact syntax. If your instance is on an older release, pick the matching documentation version from the version selector, because methods and behavior can differ between releases. Labels and menu names can differ by version, so if a heading does not match what you see, search the docs for the method name itself.
What Does the Basic Pattern Look Like?
The pattern is always the same shape, whatever the table. You create the record object for your table, add query conditions, run the query, then loop while there is another record, reading or writing fields as you go. A few method names cover almost all everyday work:
- new GlideRecord with a table name, to open the table.
- addQuery, to filter which rows come back.
- query, to run the filter and fetch the rows.
- next, to step forward through the results.
- getValue and setValue, to read and write a field on the current row.
- insert, update, and deleteRecord, to write changes back.
The docs page for each method shows the exact argument order and a short example you can adapt. Copy the example first, change only the table and field names, and test in a sub-production instance before you trust it.
Which Methods Do People Use Most?
Beyond the basics, a handful of methods come up constantly in real scripts. get fetches a single record by its sys_id, which is quicker than a query when you already know the record. addEncodedQuery lets you paste a filter string straight from a list view, which is handy for complex conditions. orderBy controls the sequence of the rows you loop through. setLimit caps how many rows come back, which matters on large tables. getRowCount tells you how many rows the query returned. For display values, getDisplayValue returns what a user would see, such as a name instead of a reference, while getValue returns the raw stored value. Each of these has its own doc page with the fine print, and the fine print is worth reading, because a few methods behave differently depending on where the script runs.
What Trips People Up?
The most common slip is forgetting to call query before looping. Without it, the loop does nothing useful, and the script fails quietly. The second is looping through a huge table with no filter, which drags the instance down; always narrow the query first, and use a limit when you only need a sample. The third is assuming a GlideRecord works the same everywhere. It is designed for server-side scripts, and using it in a client script is not supported, so client-side work goes through a different API with a similar name. The docs state this clearly on the main page, and it is the single most valuable sentence there. Also remember that field access inside a loop reflects the current row, so read the values you need before stepping to the next record.
How Do You Test a Script Safely?
Write the script in a sub-production instance, or in your personal developer instance if you have one. Run it from a place where you can see the output, such as a background script area in the instance, and log what the query returns before you let the script change anything. Comment out the update or insert line while you check the loop, then put it back once the reads look right. If a query returns nothing, print the encoded query and paste it into a list view filter to see whether the filter itself is the problem. When something still misbehaves, the method page in the docs usually has a note about the exact condition you hit, and the developer community forum is the place where the odd cases are already answered.