Trying to fetch user details via GlideAjax

Roshini
Giga Guru

Hi Team,

Am trying with below client script and server side script to get the alert message on form for the selected caller.

Client script 

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

   //Type appropriate comment here, and begin script below

   var alertDetails = new GlideAjax('UserLearning');
   alertDetails.addParam('sysparam_name','userDetails');
   alertDetails.addParam('sysparam_userid', newValue);
   alertDetails.getXMLAnswer(details);
   function details (detail)
   {
    if (detail)
    {
    var a = JSON.parse(detail);
    alert("email is " + a.email);
   }
   }
   
}
Script include
var UserLearning = Class.create();
UserLearning.prototype = Object.extendsObject(AbstractAjaxProcessor, {
   
userDetails: function(){
    var id = this.getParameter('sysparam_userid');
var gr = new GlideRecord('sys_user');
gr.get(id);
 var userObj ={
    "email": gr.getValue("email"),
 };
 
 return JSON.stringify(userObj);
 
},
    type: 'UserLearning'
});
But am not getting null, can someone help me out to find the error
1 ACCEPTED SOLUTION

SN_Learn
Kilo Patron
Kilo Patron

Hi @Roshini ,

 

All code is correct, just a mistype is there which is causing the issue.

 

In Catalog Client Script, Instead of:

alertDetails.addParam('sysparam_name','userDetails');
alertDetails.addParam('sysparam_userid', newValue);

 It will be:

alertDetails.addParam('sysparm_name','userDetails');
alertDetails.addParam('sysparm_userid', newValue);

 

In the Script include, Instead of:

var id = this.getParameter('sysparam_userid');

It will be:

var id = this.getParameter('sysparm_userid');

 

The rectified final code will be:

 

Script Include:

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

    userDetails: function() {
        var id = this.getParameter('sysparm_userid');
        var gr = new GlideRecord('sys_user');
        if (gr.get(id)) {
            var userObj = {
                "email": gr.getValue("email"),
            };
            return JSON.stringify(userObj);
        }
    },
    type: 'UserLearning'
});

 

Catalog Client script:

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

    var alertDetails = new GlideAjax('UserLearning');
    alertDetails.addParam('sysparm_name', 'userDetails');
    alertDetails.addParam('sysparm_userid', newValue);
    alertDetails.getXMLAnswer(details);

    function details(detail) {
        if (detail) {
            var a = JSON.parse(detail);
             alert("email is " + a.email);
        }
    }

}

 

The output is:

 

SN_Learn_0-1720380939410.png

 

 

 

Mark this as Helpful / Accept the Solution if this helps

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

View solution in original post

5 REPLIES 5

Thanks a lot, it was typo error