0% found this document useful (0 votes)
0 views11 pages

Glidesystem API

The GlideSystem API is a JavaScript class in ServiceNow that allows developers to interact with the platform's database and user interface without writing raw SQL. It provides various methods for user session analysis, system diagnostics, configuration retrieval, and event automation. Key methods include adding messages, queuing events, retrieving user details, and checking user roles, all aimed at enhancing user experience and system functionality.

Uploaded by

vagesh hiremath
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views11 pages

Glidesystem API

The GlideSystem API is a JavaScript class in ServiceNow that allows developers to interact with the platform's database and user interface without writing raw SQL. It provides various methods for user session analysis, system diagnostics, configuration retrieval, and event automation. Key methods include adding messages, queuing events, retrieving user details, and checking user roles, all aimed at enhancing user experience and system functionality.

Uploaded by

vagesh hiremath
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

GlideSystem API

• Glide APIs are JavaScript classes provided by ServiceNow to let


developers customize, extend, and interact with the platform’s
database, user interface, and system components. These classes are
natively optimized for ServiceNow and remove the need to write raw
SQL queries.

• One of the powerful features of ServiceNow is the GlideSystem API,


which provides a plethora of methods to retrieve information about the
system, the current logged-in user, and date/time information, among
others. This article will delve into a detailed exploration of various
essential methods offered by the GlideSystem API.

Core Use Cases of GlideSystem


• User Session Analysis: Check the currently logged-in user's details,
active roles, and permissions.
• System Diagnostics & Logging: Write system messages, debug
applications, and monitor runtime behavior.
• Configuration Retrieval: Fetch system properties dynamically to adapt
script behavior without hardcoding.
• Date & Time Operations: Calculate ranges, parse system time zones,
and construct date-based queries.
• UI Feedback: Push immediate informational or error alerts directly
onto the user's browser interface from server-side scripts.
• Event Automation: Trigger workflow events, queue background email
notifications, and schedule automation scripts.
GlideSystem - Global
• The GlideSystem API, globally accessible through the variable name
‘gs’ in server-side JavaScript, is a powerful tool that facilitates various
functionalities such as error handling, event management, and
message display, enhancing the overall user experience and system
functionality.
• Methods of Glidesystem API are as follows:

1. addErrorMessage Method
Description:
The addErrorMessage method is used to add an error message for
the current session, which can be retrieved later. This is particularly
useful for validation and user feedback during form submissions or
data processing.

Input:

Output:
2. addInfoMessage Method

Description:

The addInfoMessage method is instrumental in adding informational


messages to the current session. These messages can be used to guide or
inform the user regarding the operations being performed.

Inputs:

• message: The informational message to be added.

Input:

Ouput:
3. addMessage Method
Description:
The addmessage method is a generic method to add messages of various types, such
as error or info, to the current session. It provides a flexible way to communicate
different types of messages to the users.
Inputs:
• Type of message, such as error or info.
• message to be added to the current session.
Input:

Output:

4. eventQueue Method
Description:
The eventQueue method allows queuing an event for the event manager,
facilitating asynchronous processing and enhancing system performance and
responsiveness.
Input:

Output:

You can view it under:


System Logs → Events

5. eventQueueScheduled Method
Description:
The eventQueueScheduled method is similar to the eventQueue method but
allows scheduling the event for a specific date and time, providing enhanced
control over event processing.

6. getDisplayValueFor Method
Description:
The getDisplayValueFor method is used to retrieve the display value of a
specified field on a specified record in a particular table. This method is
useful for getting readable values for reference fields or choice fields where
the actual value stored in the database might be a sys_id or numeric value.
Input:
Output:

7. flushMessages Method
Description:
The flushMessages method in the GlideSystem API is used to clear all
session messages that were previously saved
using addErrorMessage() or addInfoMessage(). These session messages are
typically displayed at the top of the form and can be cleared to manage the
messages shown to the user effectively.
Input:

Output:

(Normally, if you only had:

[Link]("Incident is being created.");

You would see a blue message at the top of the form:

Incident is being created.

But because you called:

[Link](); the message is removed before it is displayed )


8. getCurrentScopeName Method
Description:
The getCurrentScopeName method returns the name of the current application
scope in ServiceNow. Knowing the current scope is essential to ensure that
the correct resources, such as scripts and workflows, are being accessed
and executed within the intended application scope.
Input:

Output:

9. getDateFormat Method
Description:
The getDateFormat method returns the date format associated with the current
user in ServiceNow. This is useful for formatting and displaying dates
according to the user’s preferences.

10. getDateTimeFormat Method


Description:
The getDateTimeFormat method is used to retrieve the date and time format
associated with the current user in ServiceNow. This allows for the consistent
presentation of date and time values in a format that aligns with the user’s
preferences.
Input:

Output:

11. getUser Method


Description:
The getUser method returns a reference to the user object for the
current user in ServiceNow. This allows for the retrieval of various
user attributes and details, facilitating user-specific customizations
and functionalities.

12. getUserID Method


Description:
The getUserID method returns the sys_id of the current user. This
unique identifier can be used to reference specific user records
within various parts of the application.
13. getUserName Method
Description:
The getUserName method returns the username of the current user. This is
the unique name that the user uses to log in to the ServiceNow application.

Input:

Output:

14. hasRole Method


Description:
The hasRole method determines if the current user has a specific
role or any one of multiple roles passed as a comma-separated
string. It is essential for controlling access and permissions within
various functionalities of the application.
Input:

Output:

15. hasRoleInGroup Method


Description:
The hasRoleInGroup method checks whether the current user has
a specific role within a specified group. This is useful for more
granular access control based on user roles within specific groups.

Input:
Output:

You might also like