What's wrong with my GlideAjax?

RFJ1
Tera Contributor

I wrote a simple glide ajax to get caller's email address and add it to the short description.

Apparently, the script include part is not invoked and I am not able to see logs. Please identify the issue.

 

RFJ1_0-1723192170633.png

 

RFJ1_1-1723192298398.png

 

RFJ1_2-1723192324435.png

 

Thanks!

6 REPLIES 6

Rajesh Chopade1
Mega Sage

Hi @RFJ1 

Please try provided scripts in your script include and client script:

Script include

var CallerInfo = Class.create();
CallerInfo.prototype = {
    initialize: function() {},

    getCallerEmail: function(callerId) {
        var user = new GlideRecord('sys_user');
        if (user.get(callerId)) {
            return user.email;
        }
        return '';
    },

    type: 'CallerInfo'
};

 

OnChange client script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }

    var callerId = g_form.getValue('caller_id');
    if (callerId) {
        var callerEmail = '';
        
        var ga = new GlideAjax('CallerInfo');
        ga.addParam('sys_id', callerId);
        ga.getXMLAnswer(function(response) {
            callerEmail = response.responseXML.documentElement.getAttribute("answer");
            if (callerEmail) {
                var shortDescription = g_form.getValue('short_description');
                g_form.setValue('short_description', shortDescription + ' - ' + callerEmail);
            }
        });
    }
}

 

I hope my answer helps you to resolve your issue, if yes mark my answer helpful & correct.

THANK YOU

rajesh chopade.

Simon Christens
Kilo Sage

gr.get() retrieves the user record.
So you shouldnt use if(gr.next()) - just gr.get() and then pick the email to return

AMan1997
Tera Guru

Hi @RFJ1 ,

 

Can I know which log is not visible?
Is it first one 'entering script include' or both first and last?

Thanks,

RFJ1
Tera Contributor

Both