Introduction to GlideRecord Java class and Query methods

Unknown | 06:23 | 0 comments


Glide:

ServiceNow company name used to be called as Glidesoft, Inc. incorporated in California. Glide name has been incorporated from previous company name.

GlideRecord is a special Java class (GlideRecord.java) that can be used in JavaScript exactly as if it was a native JavaScript class.


 Usage:

ServiceNow GlideRecord class is used for querying ServiceNow database to retrieve the one or more records

DB Operations Supported by Glide Record:

1. Update
2. Insert
3. Delete
4. Query
5. Get
6. Set
All 6 different DB operations are provided with multiple function/methods to achieve different use cases. In this post we will learn few examples
Use case 1:
List all incident record numbers in incident table

Where should we execute sample code: 

Before we execute the sample GlideRecord code snippet. We should provide security permission

1. Open ServiceNow UI and Click on LOCK icon on Banner section

 
 2. Tick security_admin option(This is required, because we are operating over DB records
 3. Click OK
 4. Open the coding PAD by appending URL shortcut to the URL(sys.scripts.do)


5. Write the sample code in Run script section and Click on Run button


Alternative Method How to find the Scripts - Background Utility

1. Login as an Admin User
2. Elevate your security privileges to security_admin. Click the Lock icon next your name on the title
    Bar
3. Click the security_admin checkbox and click ok. The Lock icon is now unlocked
4. Go to System Defintion > Scripts - Background.  The Scripts - Background Utility appears.

========================================================================


//Function definition
ListallIncident();

//Function Body
function ListallIncident() 
{
    var ListallIncident = new GlideRecord('incident'); ////Indicate the table to query from
    ListallIncident.query(); ////Execute the query
//Do something with the records returned
     while(ListallIncident.next()) //Operate over all incidents
     {
        gs.print('Incident Found: '+ListallIncident.number); //Print all incidents
     }
}













 

Category: , , ,

handsonbook.blogspot.com

0 comments