Introduction
In this topic we discuss very basic glide quires that we can use in ServiceNow.
This scripts
are mostly for beginners in ServiceNow.
Any data operation is done via CRUD (Create
Read
Update
Delete
).ServiceNow too have a rich set of functionality in Glide Object that helps
to make changes in data model.Lets us go through few scripts below
Basic CRUD script
Add Query
Select Query
Objective: Get
all the list of incidents
Update Query
Objective: update
all active incident to inactive
Insert Query
Objective: Insert
a new incident
Delete Query
Objective: Delete
inactive incidents
Add EncodedQuery
A easy way to use encoded query is first create the required filter in ServiceNow table.
Right click on the filter and click “copy query”
Then write the script with addEncodedQuery
and paste the query inside ()
Note: This CANNOT be used in client script and UI policy
OR Query
The standard addQuery
parameter acts like an and
condition in our query.
This example shows how we can add ‘or’ conditions to our query.
Objective: Find all incidents with a priority of 1 or 2
Glide Aggregate
GlideAggregate
is actually an extension
of the GlideRecord object. It allows you to perform the following aggregations on query record-sets.
- COUNT
- SUM
- MIN
- MAX
- AVG
Objective: Find all active
incidents and print a count
of records
O/P:
[0:00:00.004] Script completed in scope global: script
*** Script: Active incident count: 2646O/P:
Objective: Get a count of all the open incidents by category
O/P: [0:00:00.017] Script completed in scope global: script
*** Script: there are currently 1 incidents with a category of database
*** Script: there are currently 4 incidents with a category of hardware
*** Script: there are currently 2629 incidents with a category of inquiry
*** Script: there are currently 4 incidents with a category of network
*** Script: there are currently 6 incidents with a category of software
OrderBy and OrderBy Descending
We can order the results of our record set by using orderBy
and/or orderByDesc
O/P:[0:00:00.467] Script completed in scope global: script
*** Script: INC0000001
*** Script: INC0000002
*** Script: INC0000003
*** Script: INC0000004
*** Script: INC0000005
*** Script: INC0000006
*** Script: INC0000007
*** Script: INC0000008
*** Script: INC0000009
*** Script: INC0000010
Set Limit
setLimit can be used to limit
the number of results returned
O/P:[0:00:00.467] Script completed in scope global: script
*** Script: INC0000001
*** Script: INC0000002
*** Script: INC0000003
*** Script: INC0000004
*** Script: INC0000005
*** Script: INC0000006
*** Script: INC0000007
*** Script: INC0000008
*** Script: INC0000009
*** Script: INC0000010
Set Workflow
setWorkflow is used to enable/disable the running of any business rules that may be triggered by a particular update.
Add Null & Not Null Query
When addNullQuery()
is called on a GlideRecord object, it adds a condition to your query, stating that the field passed into the method call must be null (empty).
When the addNotNullQuery()
method is called with a field name as an argument, a condition is added to your query stating just the opposite - that the field must contain a value - any value. It must be NotNull.
In this case, query will print the incident numbers where the assignment_group field have value, but the assigned_to field does not have a value.
GetDisplayValue()
getDisplayValue() is quite simple, as it accepts no arguments, and returns the display value for the record upon which it’s called.
getValue()
getValue() returns the value of a specific field
or column
.
This can be the sys_id column, or any other column that might contain a value.
Conclusion
That’s all for now. Hope these queries will give you some idea on CRUD operation in ServiceNow. Have a look at advance glide scripts too.
- Understanding Request, RITM, Task in ServiceNow
- Steps to create a case in ServiceNow (CSM)
- Performance Analytics in 10 mins
- Event Management in 10 minutes - part1
- Event Management in 10 minutes - part2
- Custom Lookup List
- Script includes in 5 minutes
- Interactive Filter in 5 minutes
- UI Policy in 6 Minutes
- Client Side Script Versus Server Side Script in 3 minutes
-
Snow
- Performance Analytics
- ServiceNow Scripts
- Script include
- Useful scripts
- Basic Glide Scripts
- Client Script
- Advance Glide Script
- Glide System Script
- Admin
- Import Set
- Work Flow
- ACL
- SLA
- Notification
- Core Application
- UI Policy
- UI Action
- Client Script
- CAB Workbech
- Data Policy
- Connect Support
- Catalog
- Discovery
- CSM
- Event Management
- HR
- Integrations
- SSO Integration
- LDAP Integration
- SCCM Integration
- AWS Intergration
- Slack Integration
- CTI Integration
- Jira Integration
- Ebonding ServiceNow
- SOAP Integration
- IBM Netcool Integration
- VIP Mobile App Integration
- Rest Integration
- Service Portal
- Questions
- ACL
- Performance analytics(PA) Interactive Filter
- Various Configurations in Performance analytics(PA)
- Service Portal
- Performance Analytics(PA) Widgets
- Performance Analytics(PA) Indicator
- Performance Analytics(PA) Buckets
- Performance Analytics(PA) Automated Breakdown
- Client Script
- Rest Integration
- Understanding the Request, RITM, Task
- Service Catalogs
- Events in ServiceNow
- Advance glide script in ServiceNow
- CAB Workbench
Comments