Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

GlideAjax script not reflecting output on form (no email displayed)

sirijonna82
Mega Contributor

I’m trying to use GlideAjax to fetch the Caller’s email from the sys_user table and display it when I select a Caller on the form.

I’ve written both the Client Script and Script Include, and the script runs without errors, but the output is not reflecting on the form (alert not showing any value). If anyone knows what's the issue, please help me.

 

sirijonna82_0-1760692755766.png

sirijonna82_1-1760692786498.pngsirijonna82_2-1760692804693.png

 

1 ACCEPTED SOLUTION

M Iftikhar
Tera Sage

Hi @sirijonna82 ,

 

It looks like your Script Include and Client Script have a few small syntax and naming issues, that’s why your GlideAjax call isn’t returning anything.

 

Here's a complete working code:
Script Include:

var getEmailId = Class.create();
getEmailId.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getEmailId: function() {
        var callerId = this.getParameter('sysparm_value'); // caller sys_id
        var user = new GlideRecord('sys_user');
        if (user.get(callerId)) {
            return user.getValue('email');  // always use getValue for consistency
        }
        return ''; // fallback
    },
    type: 'getEmailId'
});

MIftikhar_0-1760718879776.png

 

Client-script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
    var ga = new GlideAjax('getEmailId');
    ga.addParam('sysparm_name', 'getEmailId'); 
    ga.addParam('sysparm_value', g_form.getValue('caller_id'));
    ga.getXMLAnswer(function(answer) {
        g_form.setValue('u_email', answer);
    });
}

MIftikhar_1-1760718970954.png

 

The Output:

MIftikhar_2-1760719036929.png

 

If my response helped, please mark it as the accepted solution so others can benefit as well.

Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.

View solution in original post

1 REPLY 1

M Iftikhar
Tera Sage

Hi @sirijonna82 ,

 

It looks like your Script Include and Client Script have a few small syntax and naming issues, that’s why your GlideAjax call isn’t returning anything.

 

Here's a complete working code:
Script Include:

var getEmailId = Class.create();
getEmailId.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getEmailId: function() {
        var callerId = this.getParameter('sysparm_value'); // caller sys_id
        var user = new GlideRecord('sys_user');
        if (user.get(callerId)) {
            return user.getValue('email');  // always use getValue for consistency
        }
        return ''; // fallback
    },
    type: 'getEmailId'
});

MIftikhar_0-1760718879776.png

 

Client-script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
    var ga = new GlideAjax('getEmailId');
    ga.addParam('sysparm_name', 'getEmailId'); 
    ga.addParam('sysparm_value', g_form.getValue('caller_id'));
    ga.getXMLAnswer(function(answer) {
        g_form.setValue('u_email', answer);
    });
}

MIftikhar_1-1760718970954.png

 

The Output:

MIftikhar_2-1760719036929.png

 

If my response helped, please mark it as the accepted solution so others can benefit as well.

Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.