GlideAjax Returning Empty Value While Fetching Caller Mobile Number from sys_user Table in Incident

DurgaPrasadCH
Mega Contributor

Hi Everyone,

I am learning GlideAjax in ServiceNow and trying to auto-populate Caller Phone Number on the Incident form.

Scenario:
When Caller is selected, I want to fetch the caller's mobile phone number from the sys_user table and populate it into a custom field u_caller_phone.

Issue:
The GlideAjax is executing, and the alert is triggering, but the answer is coming back empty even though the selected user has a mobile phone number populated.

Below is my Script Include:

var Caleerphonenumber = Class.create();
Caleerphonenumber.prototype = Object.extendsObject(AbstractAjaxProcessor, {

callerNumber: function() {

    var number = this.getParameter("sys_number");

    var Cell = "";

    var gr = new GlideRecord("sys_user");

    if (gr.get(number) && gr.mobile_phone) {

        Cell = gr.mobile_phone.getDisplayValue();

    }

    return Cell;

},

});

Client Script:

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

if (isLoading || newValue === '') {
    return;
}

var gr = new GlideAjax("Caleerphonenumber");

gr.addParam("sysparm_name", "callerNumber");

gr.addParam("sysparm_number", newValue);

gr.getXMLAnswer(function(answer) {

    alert(answer);

    g_form.setValue("u_caller_phone", answer);

});

}

Additional Details:

  • Alert is triggering successfully with empty value 
  • Caller has mobile number but not populated
  • Script Include is Client Callable

Could someone please help identify what I am missing here?

Thanks in advance.

0 REPLIES 0