- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2022 11:09 PM
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);
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2022 11:16 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2022 11:16 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2022 11:25 PM
Hi Ankur , Everything is in global scope. Your script worked. But I am trying to understand what's wrong in my script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 12:13 AM
Hi,
try to add gs.info() in script include and alert in client script
Please mark my response helpful as well.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader