what is the difference between glide ajax and call back function

Shilpi Sharma2
Tera Contributor

Hi All,

I want to know what is the difference between callback function and glide ajax in simple terms. Please help.

5 REPLIES 5

Nirosha Uddandi
Kilo Guru

https://community.servicenow.com/community?id=community_question&sys_id=bae21dfadb9ad3c0b61ff3231f9619e6&view_source=searchResult

Ravi T
Tera Guru

Hi Shilpi,

GlideAjax is used to call a script include from a client side script.

 

Callback functions are used to perform asynchronous execution of the code

For more information about call back function refer the below link

https://ahmeddrar.wordpress.com/2014/08/01/understand-callback-function-in-servicenow/

Regards

Ravindra

Dxsherpa.com

 

Santosh_Ksagar
Mega Sage
Mega Sage

Hi Shilpi,

GlideAjax used to call script include in client script. Glideajax can be asynchronous or synchronous.

Callback function is a function which is passed as a parameter to other function.

for e.g

function onChange(control, oldValue, newValue, isLoading) {

  var caller = g_form.getReference('caller_id', doAlert); // doAlert is our callback function
}
function doAlert(caller) { //reference is passed into callback as first arguments
  if (caller.vip == 'true')
  alert('Caller is a VIP!');
}

Hope this has cleared your doubt.

Mark Correct/Helpful

 

Regards

Santosh Kshirsagar

Bhartendu1
Kilo Contributor

GlideAjax is an Asynchronous call invocation to server.

Callbacks in Javascript are asynchronous by default.

 

To understand the difference create two scripts. One script with GlideRecord API call and a corresponding callback function. In the second script do the same transaction using GlideAjax and corresponding callback call. In the first script, GlideRecord API call would be synchronous, it will wait and consume the thread until and unless the response is received. Once the response is received, the callback would be called in an asynchronous way i.e. while calling the callback, other executions can happen.

Now in the second script, Glide Ajax call would be asynchronous as well as the callback function call. Here no one will wait for the response to come synchronously and other execution will proceed. The second way will increase the better user experience, performance and reduce the latency of any client-side activity.