ServiceNow Glide Ajax Tutorial | Glide Ajax example ServiceNow

Article briefs GlideAjax in ServiceNow with examplesSynchronous GlideAjax and Asynchronous GlideAjax has been demonstrated theoretically and practically. ServiceNow GlideAjax video tutorial link has been given in this article which will provide you good practical understanding of the concept and help you to implement the same.

glideajax in servicenow,servicenow tutorials,servicenow glideajax,servicenow training

In this ServiceNow Tutorial, we will talk about ServiceNow GlideAjax concepts. Concepts such as what is glide ajax in ServiceNow, types of glide ajax in ServiceNow, call back functions, asynchronous and synchronous glide ajax, scripting example and scenario based examples of glide ajax in ServiceNow.

What is GlideAjax in ServiceNow?

GlideAjax is a class in ServiceNow which is used to execute server side code from client side. Client side scripts can be Client script, UI policies, UI script etc. So, definition clearly says that we must define GlideAjax in client side scripts. But the Server side code which has to be executed through GlideAjax class should be defined in Script Include. 

While defining GlideAjax call in client side script we have should take care of below points:
  • We should initialize GlideAjax with name of script include which we have to use. 
  • The script includes which we will use, we should make sure that client callable checkbox must be checked.

The client-side script passes parameters using GlideAjax to the Script Include. The parameter uses naming conventions.

For more information on ServiceNow GlideAjax, you can refer below link:
Click for GlideAjax ServiceNow Video Tutorial

So make sure that the naming convention must have prefix “sysparm_”. For example, GlideAjax pass function name in parameter which it requires to execute at server end. Some example syntax are mentioned below:

  • ga.addParam('sysparm_name','scriptIncludeFunctionName')
  • ga.addParam('sysparm_firstname','Arthur')
  • ga.addParam('sysparm_location','Florida')

The main benefit of GlideAjax is that, we can easily calls pass parameters to the ServiceNow script include and using naming conventions. 

**Remember that 'sysparm_name' is always used for parameter function (the function which has to executed in script include) and getXML (), getXMLWait () functions are used to execute the code.

So here the question is, that why we execute server side code from client side?
There are lot of scenario, where to validate the things we need to execute server side code from client side. Let’s take an example of incident form, requirement is that the End User can only submit the incident form, when his manager belongs to any specific group (for example XYZ group). So here for validation we can get managers group name from the database or from server. So, in this scenario we execute server side code for validating the details.

Different type of GlideAjax in ServiceNow with examples?

We can call execute glide ajax code in two ways synchronously and asynchronously. So, we can say it is of two types:

Asynchronous GlideAjax ServiceNow

In Asynchronous GlideAjax we use getXML () call back functions, through which code run on backend to get the response from server. So, because of that user can proceed with other fields filling etc.

Synchronous Glide Ajax in ServiceNow

Synchronous GlideAjax use getXMLWait () function, so user cannot process with other fields filling or other fields will get freeze until the response is not received from the server.

The main difference between Asynchronous GlideAjax and Synchronous GlideAjax in ServiceNow:

Difference is that,in Asynchronous GlideAjax we use getXML () call back function where user can move to other fields as response from server process is going on backend.
Where as In Synchronous GlideAjax we use getXMLWait () function where user cannot move to other fields until the response is received from server.

Example of Synchronous GlideAjax ServiceNow:

  • For example in Login window, until the username and password are not validated user cannot proceed further.
  • In a form, if one field in dependent on another field than we can use Synchronous GlideAjax. Such as Location and Time zone. If the user selects the location, then based on location time zone will get populated. So, till the time zone is loading user must wait for the same.

Example of Asynchronous GlideAjax ServiceNow:

In a form if one field is not dependent on another field than we can use Asynchronous GlideAjax. Let’s say user is filling registration from but the forms fields are not dependent on each other. For example, FirstName, Email ID, Last Name etc.

Actually, It depends on us that for what requirement we are coding. Do we want user to proceed with other fields while process is running on or do we want user to wait until the response is received from the server?

But for normal operation always use Asynchronous GlideAjax. For better and seamless end user experience.

Glide Ajax Example ServiceNow (Scripting)

let’s take scenario in incident form, when user change the value in  short description field, then message pop up with display the total count on incidents have same description.

Code of Asynchronous GlideAjax: 

In Asynchronous GlideAjax, we use callback function.
Asynchronous GlideAjax ServiceNow Example,servicenow glideajax,glideajax servicenow
Asynchronous GlideAjax ServiceNow Example

Code of Synchronous GlideAjax:

In Synchronous GlideAjax, we do not use call back function.
Synchronous GlideAjax ServiceNow Example,servicenow glideajax,glideajax servicenow

What is call back function?

The function is said to be callback function, when it is passed as an argument to another function so that it can be called back later. This function is used to avoid application halt while the data is being fetched from the database or server.
Example is mentioned below:
Asynchronous GlideAjax Call Back Function
Asynchronous GlideAjax Call Back Function

We hope all the above information related to ServiceNow glide ajax will provide you complete theoretical and practical understanding of glide ajax in ServiceNow. Please provide you feedback in below comment box and let us know if you need more information of glide ajax examples ServiceNow or or of any other ServiceNow concept.


Thankyou !!!!

Powered by Blogger.