GlideRecord Introduction

Mark Miller
A free video tutorial from Mark Miller
ServiceNow Guru
4.4 instructor rating • 5 courses • 38,879 students

Lecture description

An introduction to the most important ServiceNow API, the GlideRecord!

Learn more from the full course

The Complete ServiceNow Developer Course

Learn how to develop on the ServiceNow platform!

08:41:44 of on-demand video • Updated October 2019

  • Develop on and customize for the ServiceNow platform
  • The ServiceNow APIs
  • When & where to script in ServiceNow
English [Auto] Hello and welcome to section for now that we've reviewed where we can apply scripts and introduce the concept of an API. It's time for us to look at our first service now API. The glidin record will serve this section with an introduction to glide record followed by a quick analogy to help solidify our understanding will then jump into the show me the code section where it will go over a brief snippet of code to show you what exactly the API looks like in a scripting environment. After that we'll cover a very important topic in service now called Dot walking. Next we'll cover the glide record API diagram where we'll take a look at some of the properties and methods associated with GLAD record. We'll then look at a list of common glad record methods and discuss the functionality behind them. After that we'll discuss the stages of a glider record and then we'll walk through the acronym crud and how it applies to the glad record once we've covered these topics then we can finally jump in the service now and actually start writing some code and background scripts after the demo will discuss glad record secure and the glide aggregate API and finally we'll end the section by discussing when we can use these API is a little bit about best practices and then go over the API documentation. Finally at the end of this section you'll find exercises as well as quizzes for you to try. All right so before I introduce the glad record let's first talk about a fundamental concept about web applications or really just any application that persists data which means that storing data for long term. So let's say we have our application server here on the left and our database server on the right. Let's say we would like to access data that is stored in the database. For example we'd like to access data about a specific incident well because service now uses my Escudo as its database. And since my escrow is a relational database management system will have to write some as well in order to retrieve the data. But it turns out as Cuil can be a bit tricky and just really not very fun to work with. So we as the developer want an easier way to access and interact with this data. It turns out we can do so by introducing an API specifically designed to do just this. Here we have what we'll call our database API for now which kind of acts like a middleman as the developer. Instead of writing Eskew Well we can access data in the database by interacting with the API via javascript because we've introduced javascript. Now we have the power of a for object oriented programming language at our fingertips. This gives us a level of abstraction that helps with security ease of use and powerful Hoeber functions. Well it turns out this database API is called glider record which is what we'll be discussing in this section glad record is the most common API you will use as a service now developer this API is accessible to the developer on the server side and is used for any type of database operation commonly summed up with the acronym crud. Crud is an industry term used to refer to the four functions of persistent storage which are create read update and delete anytime you need to read an existing user record. Create a new incident update an existing problem record or delete a change. You will use the glad record API to perform the database task. As mentioned before this API generates the best you have for us. So we as the developer don't have to worry about writing Eskdale from scratch. We can think of the glad record as having two stages and the first stage we build out the actual query. So we'll select the table we want to query on and start to build out the filter that we apply to the rescue. For example we could say we want to show all priority 1 incidents that were created within the last two weeks. Again we can create this filter and this happens within the first stage once the first stage is complete. The actual As L is sent to the database where the records are received back from the database and you can think of the second stage starting at that point in time. Now in the second stage of our glide record we can think of this as a collection of records or a list of records from the query table. This is where we do the actual processing of the records. So for example if we wanted to update specific fields or even delete certain records we could do so here. And this stage of the glad record you can think of it as being an ordered list of records for example when we view a list of incidents on the incident table glide record is being used behind the scenes to query the database and retrieve the data related to a specific filter of incidents. All right. So before we go any further I'd like to first introduce you to the show me the code slide. Now I understand the slide may be a bit overwhelming to some of you but don't worry we'll cover all of these topics later on in this section. The goal of this slide as well as the show me the code slides in future sections is to give you a practical example as soon as possible providing you the student with a holistic approach. Now I could talk for hours on the theory and concepts of glad record but that won't to do you the student much good in learning this topic for the first time. This is why it went up taken programming courses in the past. I've always enjoyed instructors who take a moment early on when introducing a new concept to show some actual code. So if you do not understand a certain concept in this slide or in future show me the code slides. Feel free to even skip the slide and power through the rest of the section. All right so in this example we'll start simple. We'd like to print a list of all priority one incident's to the screen. Now let's walk through this line by line on line 1. We are instantiating an object by calling the new keyword along with the constructor glide record. We pass in one argument which is the system name of the table we'd like to query. This is simply a string type. We then assign this to a variable named incident G.R. for glide record. Note that it is best practice to give meaningful names to variables such as incident G.R. instead of simply G.R. throughout this course. When I am teaching the concept of glider record I will typically use the name of the table or record that I will be querying from along with a capital G.R. afterward to signify that this is a glide record object but feel free to come up with your own convention. As long as it's related and has some type of contractual meaning to what you are doing so now that we have the glide record object assigned to the incident G.R. variable we can start to call methods on the object online too. We can call the ADD query method which accepts two arguments first a string which is the name of the records field. We would like to filter on and the second argument is the system value. This add query method is very similar to something you would see in the GUI interface or the back end of service now. When you apply a certain filter to a table so even on the incident table if you click the filter icon you can apply these conditions to the filter. Well it turns out that this gooey interface is actually using the glide record API in the background and using something very similar to what we've defined here on line to on line 3. We performed the actual database query operation which generates the actual Eskew for us sends it to the database for to get processed and then returns the records to us. And a javascript object it's the query method that ends stage 1 of the glide record and starts. Stage 2 of the record where we can then think of everything after this line as a list of records. In this case incident's online for we can use a javascript while statement to loop through all of their returned records. We use the glide record next method to determine if there is another record in the array. If so we continue to line 5 so finally online five we use another service now API glide system which is referenced with G-S in order to print the incident number to the screen. Note that we are able to access the number fuelled by simply adding a period followed by the name of that field. All right. Now let's take a step back and I'll provide a very simple analogy for glide record and this analogy will be buying groceries at a grocery store and the process is as follows. First you'll select which grocery store we'd like to go to. This can be analogous to selecting a database table to query. Second will grab a shopping cart in the store. The current can be thought of as the glide record object third will place groceries in the shopping cart. The groceries can be thought of as records from the table every grocery item has specific attributes to it like the name its price and color these item attributes can be thought of as field values for a record like the color on an incident record. Finally it's time to check out at the cashier. This last step can be thought of as performing some kind of action on the records whether they are for display updating deleting or even creating new records. All right. So let's kind of apply this analogy to a real world example. So again using our first example we discussed in the show me the code section we'd like to print all incidents to the screen that have a priority of one. While these steps may vary depending on the glide record methods that you are using There are typically four steps involved in this process. Just like we saw an analogy. The first step is selecting a table to query. In this example it's the incident table and the second step. We build our filter if required. Again in this example it's priority one incident's the third step is where we tell service now to make the actual query against the database table along with our arguments. This is when the glider record actually generates the Escudo runs it against the minuscule database and processes the return rows into a glad record object. Again this kind of marks the end of stage 1 and the start of stage 2 Finally the fourth step is where we would process these records whether we would just be querying them deleting them or updating them. In this example we're just simply printing the numbers to the screen. We'll talk more about the stages and the third video in this section. However for now you can think of steps 1 2 and 3 as being in the first stage. The build query glad record stage and the fourth step and this diagram as being and the second stage or the process record stage. It's important to note that any service now table so any of the 2400 out of the box tables or any new tables that you create can be queried using this glide record API.