- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
04-29-2024 01:36 AM - edited 04-29-2024 02:08 AM
In the world of ServiceNow scripting, mastering "GLIDE" scripting is key—it's essentially a subset of JavaScript.
Even if you're not a JavaScript expert, understanding Glide puts you in control. So, let's dive in and get started!
Server Side Glide
The GlideRecord API:
Imagine it as the master controller of ServiceNow's data universe. It's your tool for creating, reading, updating, and deleting records in ServiceNow tables. Think of it like having a magic wand for manipulating data effortlessly! You can use it to run server-side scripts, access related records, and perform all sorts of cool data tricks.
Best Practices:
- Be smart with your queries and only grab the records you need to keep things running smoothly.
- Keep sensitive info safe by using encryption and data protection features.
- When things get complex, like dealing with multiple tables, use transactions and locking to keep everything in order.
- Boost query speed by using indexed fields and avoiding unnecessary joins.
Most Used Functions:
- .get(): Fetches a single record based on specific conditions.
- .query(): Runs a query and gives you a GlideRecord object representing the results.
- .insert(): Puts a new record into a table.
- .update(): Makes changes to an existing record.
- .deleteRecord(): Removes a record from a table.
Example :-
var gr = new GlideRecord('incident'); //Indicate the table to query from
The GlideAggregate API:
This one's your go-to for fancy data analysis and number crunching. With it, you can do advanced calculations and groupings on ServiceNow tables. It's like having a math whiz who can crunch numbers and give you amazing insights!
Best Practices:
- Keep your queries tight and efficient to keep things speedy.
- Use field indexing and query order to speed up your searches.
- Know the performance impacts of working with big sets of data.
Most Used Functions:
- .addAggregate(): Picks the field and calculation method for your data crunching.
- .addGroupBy(): Chooses which field(s) to group your results by.
- .query(): Runs the big data analysis and hands you back a GlideAggregate object.
- .next(): Moves through the grouped data.
- .getValue(): Grabs the calculated value.
Example :-
var agg = new GlideAggregate('incident');
agg.addAggregate('COUNT', 'category');
The GlideSystem API:
If GlideRecord is the data master, GlideSystem is the system wizard. It gives you access to system-level powers and info. Need system properties? Manipulate dates? Log messages? Manage user sessions? GlideSystem has your back!
Best Practices:
- Don't mess with system properties unless you really have to; there are overrides for a reason.
- Use logging to help with troubleshooting.
- Handle dates and times carefully to avoid timezone troubles.
- Keep sensitive info safe in system properties and global variables.
Most Used Functions:
- .getProperty(): Gets the value of a system property.
- .log(): Writes a message to the system log.
- .getSession(): Gives info about the current user session.
- .addErrorMessage(): Shows an error message to the user.
- .nowDateTime(): Gets the current date and time, in the local time zone.
Example :- gs.addErrorMessage()
Client-side Glide Classes
The GlideForm API:
This one's your partner in crime when it comes to forms and fields. It lets you play around with forms in the ServiceNow interface. Set values, check inputs, control what's visible, and more. It's like having a buddy who keeps your forms looking sharp!
Best Practices:
- Use both server-side and client-side checks for data safety.
- Don't overload the server with too many round trips.
- Keep your forms user-friendly with good design practices.
- Use messages and notifications wisely.
Most Used Functions:
- .setValue(): Sets a field's value.
- .getValue(): Gets a field's value.
- .setDisplay(): Controls if a field is visible.
- .addErrorMessage(): Shows an error message.
- .getControl(): Gets a reference to a field.
- .addInfoMessage(): Shows an info message.
Example :- g_form.getValue('field_name');
The GlideAjax API:
Ever need to chat with the server without reloading the whole page? GlideAjax is your hotline. It lets you talk to the server without slowing things down. It's like having a direct line to get things done faster!
Best Practices:
- Keep your calls to GlideAjax to a minimum to avoid overloading the server.
- Handle errors gracefully.
- Check and clean inputs on the server side to stay secure.
- Keep your server-side scripts efficient.
Most Used Functions:
- .getXMLWait(): Sends a request and waits for a response.
- .addParam(): Adds info to your request.
- .getAnswer(): Gets the response.
- .get(): Runs the request and handles the response.
- .getXML(): Sends a request and handles the response asynchronously.
Example :-
var ga = new GlideAjax('ScriptIncludeName');
ga.addParam('sysparm_name', 'XXX');
ga.addParam('sysparm_buildingid', YYY));
ga.getXML(CallBack);
So there you have it! These Glide APIs are like your superpowers for making ServiceNow your own. GlideRecord, GlideSystem, GlideForm, GlideAjax, GlideAggregate—they're all here to help you customize, extend, and integrate. Just remember to use them wisely and follow best practices for smooth sailing!
Thanks
Ravi Gaurav
www.youtube.com/@learnservicenowwithravi
MVP ServiceNow
- 7,276 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
This is a great document, Ravi. Very well summarized altogether.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Very good explanation. This is very educative. Thank you. Mukesh Kumar

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks for sharing. It's informative @Ravi Gaurav
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
That's a great resource to start gliding in the great skies of Glide APIs 🙂
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Good starting point. Thanks.