Hi friends, thanks for all your support.You are always my encouragement to write new content.
Seeing the response I decided to take leap forward and start composing video tutorials.
I am yet to create a hand full of them.But I am confident your subscriptions and like will be my fuel to create
more feature rich content.
If you feel it is worthy please subscribe my video channel below.
At any time you can click on the to got my youtube
channel
Advance glide script in ServiceNow
Learn advance glide scripts.
This article is a supplement to the ServiceNow documentation. For full
documentation please refer ServiceNow official website
Checkout our NEWVideo Channel you can like
and subscribe too!
Introduction
Glide is an extensible Web 2.0 development platform written in Java that facilitates rapid development of forms-based workflow applications
GlideRecord to Query Tables
In order to query a table, first create a ServiceNow object for the table. This object is called a GlideRecord.
To create a GlideRecord, create the following in script:
This issues the query() to the database. Each call to next() would load the next record.
If we wanted to find all incidents where the priority field is GREATER THAN 1
List of all operators
Null and Not null check
query
update
insert
delete
Active Inactive state
Has Attachments
True if the current record has attachments.
Add Query
1 argument adds an encoded query string.
2 arguments return records where the field is equal to the value (or is in a list of values).
3 arguments return records where the field meets the specified condition (field, operator and value).
Join tables
Parameters:
joinTable – table name.
primaryField (optional) – if other than sys_id, the primary field.
joinTableField (optional) – if other than sys_id, the field that joins the tables.
Encoded query
An encoded query string to add to the record.
Use the breadcrumbs and filters to generate encoded query strings.
Get Attribute
Gets the attributes on the field in question from the dictionary.
Display Value
Gets the attributes on the field in question from the dictionary.
Get Fields
Retrieves a Java ArrayList of fields in the current record.
Get Record ClassName
Retrieves the class name for the current record.
Get TableName
Retrieves the table name associated with this GlideRecord.
Set Workflow
Enables or disables the running of business rules that might normally be triggered by subsequent actions. If the
parameter is set to false, an insert/update will not be audited. Auditing only happens when the parameter is
set to true for a GlideRecord operation.
Parameters:
– Boolean variable that if true (default) enables business rules, and if false to disables them.
Update With References
Updates a record and also inserts or updates any related records with the information provided.
if processing a incident where the Caller ID is set to reference sys_user record David Loo then the following
code would update David Loo’s user record.
if processing a incident where there is no Caller ID specified, then the following code would create a new
sys_user record with the provided information (first_name, last_name) and set the Caller ID value to the newly
created sys_user record.
Insert With References
Inserts a new record and also inserts or updates any related records with the information provided.
If a reference value is not specified (as below), then a new user record will be created with the provided
first_name, last_name, and the caller_id value is set to this newly created sys_user record.
The result is a new sys_user record with the provided first_name, last_name and a new incident record with
the provided short_description and caller_id.
Delete Multiple
Deletes multiple records according to the current where clause. Does not delete attachments.
Set Limit
Sets the limit for how many records are in the GlideRecord.
GlideAggregate
The GlideAggregate class is an extension of GlideRecord and allows database aggregation (COUNT, SUM, MIN,
MAX, AVG) queries to be done.
an example to get a count of the number of active incidents.
MIN, MAX, and AVG
Records have been modified and we want the MIN, MAX, and AVG values
Compare activity from one month to the next
Add Aggregate
String agg – name of aggregate to add.
String name – name of column to aggregate.
Get Aggregate
Parameters:
agg – String type of the aggregate (e.g. SUM or COUNT)
name – String name of the field to get aggregate from.
Group By
Provide the name of a field to use in grouping the aggregates..
Order By
Provide the name of a field that should be used to order the aggregates. The field will also be added to the
group-by list.
Order By Aggregate
Parameters:
agg – String type of aggregate (e.g. SUM, COUNT, MIN, MAX)
name – String name of field to aggregate
Conclusion
That’s all for now…Do check out other script related post here
With 9+ years of ITSM development experience,Chandrima likes to deep dive ServiceNow modules.She have extensively worked on PA,Service Portal,Event management.
Comments