6.script Include& Glide API's
6.script Include& Glide API's
GLIDE API’S
• Glide APIs : are a set of APIs provided by the ServiceNow platform that allow developers to interact with the platform and
perform a wide range of operations. Glide APIs are built on top of the ServiceNow Glide system, which is a server-side
scripting engine that is used to perform operations on the ServiceNow platform.
• Some of the key features and capabilities of Glide APIs include:
1. Data Access: Glide APIs allow developers to access and manipulate data stored in the ServiceNow platform. This includes the
ability to create, read, update, and delete records in ServiceNow tables, as well as perform advanced operations such as
joining tables, filtering data, and aggregating data.
2. Workflow Management: Glide APIs allow developers to manage workflows and automate processes on the ServiceNow
platform. This includes the ability to create and manage workflows, trigger workflows based on events or conditions, and
monitor the status of workflows.
3. User Interface: Glide APIs allow developers to customize the ServiceNow user interface by creating custom forms, fields,
and UI elements. This includes the ability to create custom UI pages, widgets, and themes, as well as modify the behavior
and appearance of existing UI components.
4. Integration: Glide APIs allow developers to integrate the ServiceNow platform with external systems and services. This
includes the ability to connect to external APIs, consume and publish web services, and interact with other systems using
industry-standard protocols such as REST and SOAP.
• Overall, Glide APIs provide a powerful and flexible set of tools for developers to interact with the ServiceNow platform and
build custom applications, workflows, and integrations. By leveraging Glide APIs, developers can extend the capabilities of
the ServiceNow platform and create custom solutions that meet the specific needs of their organization.
• Glide API’s Method:
• Glide API methods are a set of functions provided by the ServiceNow platform that developers can use to interact with the
platform and perform a wide range of operations. These methods are organized into different categories based on their
functionality and the areas of the platform that they interact with.
• Here are some of the most commonly used Glide API methods:
1. GlideRecord: This API method is used to access and manipulate records in ServiceNow tables. Developers can use this
method to create, read, update, and delete records in tables, as well as perform advanced operations such as joining tables,
filtering data, and aggregating data.
2. GlideSystem: This API method is used to perform system-level operations on the ServiceNow platform. Developers can use
this method to access system properties, log messages, perform date and time calculations, and interact with the file
system.
3. GlideAggregate: This API method is used to perform aggregate operations on ServiceNow tables. Developers can use this
method to calculate sums, averages, and other statistical measures for groups of records in a table.
4. GlideForm: This API method is used to interact with forms and fields on the ServiceNow platform. Developers can use this
method to access form data, validate form data, and set form values programmatically.
5. GlideAjax: This API method is used to make asynchronous calls to the server and retrieve data from the ServiceNow
platform. Developers can use this method to create custom AJAX requests and update the user interface dynamically without
requiring a page refresh.
6. GlideUI: This API method is used to interact with the user interface on the ServiceNow platform. Developers can use this
method to create custom UI components, modify the behavior and appearance of existing UI components, and interact with
UI elements using JavaScript.
• These are just a few examples of the many Glide API methods available on the ServiceNow platform. By using these
methods, developers can extend the capabilities of the platform and create custom applications, workflows, and integrations
that meet the specific needs of their organization.
1. GlideRecord: This API method is used to access and manipulate records in ServiceNow tables. Developers can use this method to
create, read, update, and delete records in tables, as well as perform advanced operations such as joining tables, filtering data,
and aggregating data.
addActiveQuery(): Adds a filter to return active records.
• addActiveQuery() function that can be used to filter active records in a table.
• The addActiveQuery() function adds an active=true condition to the Glide Record query. This function is typically used when
querying tables that have an active field, such as the Incident [incident] table.
var gr = new GlideRecord('incident');
gr.addActiveQuery();
gr.query();
while (gr.next()) {
// do something with the active incident record
gs.print('active incidents are' + gr.number);
}
The addEncodedQuery():
that is used to add a pre-defined query to the current Glide Record object.
This function allows developers to apply complex, pre-built queries to their Glide Record object, without having to manually
construct a query using the addQuery() method.The addEncodedQuery() function takes a single parameter, which is a string
representing the encoded query.
• var gr = new GlideRecord('incident');
• gr.addEncodedQuery("priority=1^OR priority=2");
• gr.query();
• while (gr.next()) {
• gs.print(gr.number);
• }
addQuery(String name, Object operator, Object value):
The addQuery(name, operator, value) function in GlideRecord is used to add a new query condition to the GlideRecord object.
It takes three parameters:
name: The name of the field that you want to filter on.
operator: The operator to use in the query. This can be one of the following: <, <=, =, !=, >, >=, LIKE, NOT LIKE, IN, NOT IN, IS, IS NOT,
STARTSWITH, ENDSWITH, CONTAINS, or DOES NOT CONTAIN.
value: The value that you want to filter on. This can be any valid GlideRecord field value.
2. Using addEncodedQuery display Total number of incidents with category "servicenow" and priority 1?
• var agg = new GlideAggregate('incident');
• agg.addEncodedQuery('category=servicenow^priority=1^ORDERBYstate');
• agg.addAggregate('COUNT');
• agg.query();
• if (agg.next()) {
• var totalCount = agg.getAggregate('COUNT');
• gs.print('Total number of incidents with category "servicenow" and priority 1: ' + totalCount);
• }
• Print description and short description for any form(inc.prblm,change) by using background scripts?
• run a query in script background to show all the active incidents?