Understand Callback function in ServiceNow

In ServiceNow, there is always a need to return GlideRecord on the client side for a specific field  due several reason. for example , checking whether the caller is VIP or no? or to check if the customer has a parent company, and many other reasons depend on the business needs.

Many ServiceNow developers when they do write a script for returning GlideRecord on the client side they do it without a call back function that makes the script runs synchronously causing a hang, while waiting response back from the server.

what is callback function?

The callback function is a function that is passed as a parameter in another function and which is invoked after expected event. to have better understand of callback function , lets play some javascript

//myCallback is parameter work as callback  
function myContainer(x, y,myCallback) {
return Callback(x, y);
// calcSum is to be passed to myContainer
 function calcSum(x, y) {
return x + y;
// print out the result 

the best way to return GlideRecord :

var caller = g_form.getReference(‘caller_id’, showcallerTitle);
function showcallerTitle(caller) {

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s