_
_
Back to Blog
ServiceNow
IT Service Management
RapDev Applications

ServiceNow's Glide APIs

Dive into Glide APIs, but don't worry—we'll keep it fun and straightforward!
6
min read
|
by
Pallavi Gupta
September 7, 2023

ServiceNow's got these awesome Glide APIs that make our lives super easy as developers! They give you the power to customize, extend, and integrate the platform in ways that suit your organization's needs. Let's dive into these APIs, but don't worry—we'll keep it fun and straightforward!

Server-side Glide Classes

1. GlideRecord API

This API is like the master of ServiceNow's data world. It lets you create, read, update, and delete records in ServiceNow tables. It's like having the ability to manipulate data with a snap of your fingers! Use it to execute server-side scripts, access related records, and perform all sorts of magical data tricks.

  • Best Practices:
    Use efficient query conditions and limit the number of records retrieved to optimize performance.
    Leverage field-level encryption and data protection features for sensitive information.
    Employ transactions and locking mechanisms when performing complex operations involving multiple tables.
    Utilize indexed fields and avoid unnecessary joins to enhance query performance.
  • Most Used Functions:
    .get(): Retrieves a single record from a table based on the specified conditions.
    .query(): Executes a query and returns a GlideRecord object representing the result set.
    .insert(): Creates a new record in a table.
    .update(): Updates an existing record.
    .deleteRecord(): Deletes a record from a table.

2. GlideAggregate API

This API is your best friend if you're into complex queries and data crunching. It lets you perform advanced aggregations and grouping operations on ServiceNow tables. You can calculate sums, averages, min, max, and more. It's like having a genius mathematician who can analyze data and give you mind-blowing insights!

  • Best Practices:
    Limit the number of records retrieved and use efficient query conditions to optimize performance.
    Utilize field indexing and proper query order to improve query execution time.
    Understand the performance implications of aggregating large datasets.
  • Most Used Functions:
    .addAggregate(): Specifies the field and aggregate function to include in the aggregation.
    .addGroupBy(): Specifies the field(s) to group the results by.
    .query(): Executes the aggregate query and returns a GlideAggregate object representing the result set.
    .next(): Moves the cursor to the next aggregated result.
    .getValue(): Retrieves the value of the aggregated field.

3. GlideSystem API

If GlideRecord is the data wizard, then GlideSystem is the system magician. It grants you access to system-level functionalities and information. You can get system properties, manipulate dates and times, log messages, and manage user sessions. It's like having a friend who helps with all your system-related problems!

  • Best Practices:
    Avoid modifying system properties directly unless necessary; prefer using system properties overrides instead.
    Use logging methods effectively to facilitate troubleshooting and debugging.
    Follow best practices for date and time manipulation to ensure accurate handling of time zones and daylight saving time.
    Secure sensitive information stored in system properties and global variables.
  • Most Used Functions:
    .getProperty(): Retrieves the value of a system property.
    .log(): Logs a message to the system log.
    .getSession(): Retrieves information about the current user session.
    .addErrorMessage(): Displays an error message to the user.
    .nowDateTime(): Returns the date time in local format and the local time zone. This method is not available in scoped applications.

Client-side Glide Classes

1. GlideForm API

This API is your sidekick when it comes to forms and fields. It helps you interact with forms in the ServiceNow user interface. You can set field values, perform validations, control field visibility, and trigger form events. It also lets you manage UI elements, display notifications, control pop-ups, and dynamically manipulate UI elements. It's like having a trusty companion who ensures your forms are in tip-top shape!

  • Best Practices:
    Use server-side validations in addition to client-side validations to enforce data integrity and security.
    Leverage onChange events judiciously to minimize unnecessary server round-trips.
    Follow UI best practices for field placement, labels, and error messaging to enhance usability.
    Use notifications and messages judiciously to provide relevant and actionable information to users.
    Follow UI design principles for consistent styling and layout.
    Leverage UI policies and client scripts to enhance form interactivity.
  • Most Used Functions:
    .setValue(): Sets the value of a form field.
    .getValue(): Retrieves the value of a form field.
    .setDisplay(): Controls the visibility of a form field.
    .addErrorMessage(): Displays an error message associated with a form field.
    .getControl(): Retrieves a reference to a form field element.
    .addInfoMessage(): Displays an informational message to the user.
    .addErrorMessage(): Displays an error message to the user.
    .showFieldMsg(): Displays a message next to a form field.
    .addDecoration(): Adds CSS classes or styles to a UI element.

2. GlideAjax API

Picture this: you need to communicate between client-side and server-side scripts without refreshing the entire page. That's where GlideAjax comes to the rescue! It allows you to make asynchronous server-side calls, passing parameters, and handling responses in a flash. It's like having a secret hotline to the server, saving you time and effort!

  • Best Practices:
    Minimize the number of GlideAjax calls to avoid unnecessary server load.
    Implement proper error handling and gracefully handle any exceptions or errors that may occur during the GlideAjax calls.
    Validate and sanitize input parameters on the server side to prevent potential security vulnerabilities.
    Optimize server-side scripts to minimize execution time and resource usage.
  • Most Used Functions:
    .getXMLWait(): Sends a request to the server and waits for the response.
    .addParam(): Adds a parameter to the GlideAjax request.
    .getAnswer(): Retrieves the response value from the server.
    .get(): Executes the GlideAjax request and handles the asynchronous response.
    .getXML(): Sends a request to the server and handles the response asynchronously.

So, there you have it! These Glide APIs in ServiceNow are like your trusty superpowers for customizing, extending, and integrating the platform. GlideRecord, GlideSystem, GlideForm, GlideAjax, GlideAggregate, and many more—all ready to assist you in your development endeavors. Remember to use the most used functions wisely and follow the best practices to ensure smooth and efficient operations.

Written by
Pallavi Gupta
Boston, MA
Loves music so much she can work for lengthy periods while listening to anything. 1 part engineer, 1 part wanderer, 2 parts geek and 3 parts artist.
you might also like
back to blog