GlideAjax not working

Tapish Sharma1
Kilo Sage

hi ,

I am trying to build a UserUtils script include. But when i am trying to fetch the data through glideAjax, it is not working, below are my script - 

Script include -

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

getEmail : function(){
var usr = new GlideRecord('sys_user');
usr.addQuery('sys_id',gs.getUserID());
usr.query();
if(usr.next()){
return usr.getValue('email');
}


},
getDepartment : function(){
var usrDep = new GlideRecord('sys_user');
if(usrDep.get(gs.getUserID())){
return usrDep.department.getDisplayValue();

}
},

type: 'UserDetails'
});

 

Client Script On Load 

function onLoad() {
//Type appropriate comment here, and begin script below

var ga = new GlideAjax('global.UserDetails');
ga.addParam('sysparm_name','getEmail');
ga.getXMLAnswer(callBack);

function callback(response){
var answer = response;

g_form.addInfoMessage('Hello' + answer);
}

}

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

I assume script include is client callable

If you are in scoped application then getValue() won't work

Update as this

Script Include:

getEmail : function(){
        var usr = new GlideRecord('sys_user');
        usr.addQuery('sys_id',gs.getUserID());
        usr.query();
        if(usr.next()){
            return usr.email.toString();
        }
    },

Client Script:

function onLoad() {
	//Type appropriate comment here, and begin script below
	var ga = new GlideAjax('global.UserDetails');
	ga.addParam('sysparm_name','getEmail');
	ga.getXMLAnswer(function(answer){
		g_form.addInfoMessage('Hello' + answer);
	});
}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

I assume script include is client callable

If you are in scoped application then getValue() won't work

Update as this

Script Include:

getEmail : function(){
        var usr = new GlideRecord('sys_user');
        usr.addQuery('sys_id',gs.getUserID());
        usr.query();
        if(usr.next()){
            return usr.email.toString();
        }
    },

Client Script:

function onLoad() {
	//Type appropriate comment here, and begin script below
	var ga = new GlideAjax('global.UserDetails');
	ga.addParam('sysparm_name','getEmail');
	ga.getXMLAnswer(function(answer){
		g_form.addInfoMessage('Hello' + answer);
	});
}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur , Everything is in global scope. Your script worked. But I am trying to understand what's wrong in my script 

Hi,

try to add gs.info() in script include and alert in client script

Please mark my response helpful as well.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader