Returning values from script include in client script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2019 02:00 PM
My script include is getting values from the 'sys_user' table and 'cmdb_ci_computer' table. However the values are not returning (and not returning in my log statements).
I'm just trying to return one of the functions form my script include in my client script, but am getting a js console error: 'Unhandled exception in GlideAjax.' - old_function(text);
Need help to troubleshoot it. My client script is:
function onChange(control, oldValue, newValue, isLoading) {
//call script include to return user fields
var ga = new GlideAjax('ITSMws1Fields');
ga.addParam('sysparm_name','getPosition');
ga.addParam("sysparm_user", newValue);
ga.getXMLAnswer(setField);
}
//set position and location field values
function setField(response) {
var answer = response;
if (answer != '') {
g_form.setValue('position_title', position);
}
}
My script include set to client callable and is:
var ITSMws1Fields = Class.create();
ITSMws1Fields.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getPosition: function() {
var user_id = this.getParameter('sysparm_user');
var position = '';
var gr = new GlideRecord('sys_user');
gr.addQuery('title');
gr.query();
if(gr_user.get(user_id)) {
position = title; }
gs.log('postion');
return position;
},
getLocation: function() {
var user_id = this.getParameter('sysparm_user');
var work_location = '';
var gr = new GlideRecord('sys_user');
gr.addQuery('location');
gr.query();
if(gr_user.get(user_id)) {
work_location = location; }
gs.log('location');
return location;
},
getComputer: function(user_id) {
var ans = '';
var gr_computer = new GlideRecord('cmdb_ci_computer');
if(gr_computer.get('assigned_to', user_id))
ans = gr_computer.getUniqueValue();
gs.log('ans');
return ans;
},
type: 'ITSMws1Fields'
});
cheers
- Labels:
-
Best Practices
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2019 03:36 PM
try this
getPosition: function(){
var position = '';
var user_id = this.getParameter('sysparm_user');
var gr = new GlideRecord('sys_user');
gr.get(user_id);
position = gr.getDisplayValue('title');
return position;
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-02-2020 02:26 AM
Was anyone able to find a solution to this? I am facing the same issue as above. Please let me know