GlideAjax Introduction

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

Lecture description

In this video, we'll introduce the client-side API, GlideAjax.

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 7 where we'll be talking about the glide Ajax API. All right we have a lot to cover in this section. So we'll start off with a glide Ajax introduction then we'll cover what AJAX is in the industry and we'll talk about synchronous versus asynchronous and then we'll talk about the stages of Gladdie Jack's followed by an example showing the glide Ajax process after we have the foundation set then we'll actually jump into the show me the code slide where it will go over an example. After that we'll actually revisit script includes and discuss the role they play with Glide Ajax then we'll briefly cover the javascript callback and talk about how it's use with Vlad Ajax. Next we'll go over the difference between Jaison and SML and discuss some of the pros and cons then we'll do a glide Ajax API Harborview along with its methods and then we'll finally jump into a demo where I'll demo three separate line Ajax examples and then we'll end this section with a section recap. OK so the service not docs state the linei Jack's class enables a client script to call server side code in a script include sounds easy enough but it turns out this is more complex than some of the other scripting examples we've seen. OK so they're glad Ajax API itself is a class site API but it's actually used to call a server side script includes. So there are client side and server side components to this process. It's similar to something like jackaroos Ajax method if you're familiar with Jake we're Ajax for asynchronous javascript. X and now it was popularized by Google and Google Maps and Gmail and it's a way to make client side requests to the server side without requiring a page reload. So there's actually a browser API the SML HTP request that is used to make AJAX calls and it turns out that behind the scenes glial Ajax is actually calling this browser API to make the request but there is a layer of abstraction so we don't have to worry about that. We just interact with GLAD Ajax. So there's actually synchronous and asynchronous requests and hopefully this slide will help to shed some light on these topics. All right so let's take a look at what these words mean in the world of Web applications. So we'll start on the left hand side with synchronous and the left vertical line represents the client and then the vertical line on the right represents the server in this diagram we're going to be looking at requests from the client and responses to the server. So any asynchronous environment when the client sends a request to the server and then is waiting for the response the client is actually blocked. So it must wait for the response before it can start processing other events. So in this example we can see that. When the request is sent out the client is blocked until it receives the response back from the server. So within a synchronous environment we can see that the client or the browser is actually blocked. So it's unable to process events until it receives this response from the server. This is still a problem and fundamentally bad practice to build a web application in this nature because we're never truly sure of how long the response is going to take from the server. So if we were to travel back in time to the late 90s this response could take seconds possibly even minutes to return. And in that amount of time the client side will be completely blocked. So it'll essentially be frozen until it receives this response. Well that's where Ajax comes into play with the asynchronous component. So now let's take a look at the asynchronous side. So the right we can see that when the client sends the request that it is not blocked and in fact we can even make another request because we're not blocked. We can still compute. We can still process things so you can see here in this diagram that the client has actually made two requests without even receiving the first response it. So we can say asynchronous is nonblocking and this is exactly what we want in modern day applications. All right next let's look at the three stages of light Ajax. So in the first stage the client side code calls the glide Ajax API which behind the scenes is making an X amount HTP request to the server. So this stage is triggered by some type of event usually found in client scripts such as an onload load or when a field value changes then the code that contains the Ajax API is executed. So the second stage starts once the server receives this request from the client. So in the second stage the server side code processes the request and returns a response back to the client. So then in the third stage client side code processes the response. So we have to tell the browser what to do with the response from the server. So whether we're updating the field or doing some other type of event we have to we have to tell the browser what's going to happen once this request has been received. So we can see in the stages it kind of goes from the client to the server back to the client. And at each stage we need to explicitly tell the browser in the server what we want to do. All right and finally let's look at the two scripting locations to let Ajax. So as I mentioned before even though the glide Ajax API is a client side API we are still accessing server side code. So there are in fact two scripting locations. So the first obviously is the client side code which contains the glide Ajax API methods. These are oftentimes stored in either client scripts or UI pages and we have an example here at the bottom on the left of a UI Page's client script and then on the right we have our server side code the server side code is stored in a script and glued and on the bottom right. We have a image of a script including.