- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2017 12:31 PM
Greetings all. I'm still learning my way around Glide Ajax and know there's probably a very simple mistake in my code here but I can't see it. All I want to do is update 2 variables (location and department ) on my form when the requested for person changes.
Here's my Script Include named getRequestedForData:
var getRequestedForData = Class.create();
getRequestedForData.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserData: function() {
try {
var userId = this.getParameter('sysparm_id');
var result = this.newItem('result');
var array = [];
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', this.getParameter('sysparm_id'));
while(gr.next()) {
var object = {};
object.id = gr.getUniqueValue();
object.loc = gr.getValue('location.name');
object.dept = gr.getValue('department.name');
array.push(object);
}
var json = new JSON();
var data = json.encode(array);
return data;
}
catch(e) {
gs.log("CDL: E- " + e.message);
}
},
type: 'getRequestedForData'
});
And here's my Catalog Client Script, (OnChange based on the requeste_for variable):
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
g_form.setValue('iops_brm_location', '');
g_form.setVisable('iops_brm_location',false);
g_form.setValue('iops_brm_department', '');
g_form.setVisible('iops_brm_department',false);
return;
}
//get Requested For Data
var ga = new GlideAjax("getRequestedForData");
ga.addParam('sysparm_name','getUserData');
ga.addParam("sysparm_id",g_form.getValue('requested_for'));
confirm("ReqFor: GA Started");
ga.getXML(setReqForDetails);
function setReqForDetails(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
try{
answer = answer.evalJSON();
}
catch(e){
answer = JSON.parse(answer);
}
g_form.setValue('iops_brm_location', answer.loc);
g_form.setReadOnly('iops_brm_location',true);
g_form.setVisable('iops_brm_location',true);
g_form.setValue('iops_brm_department', answer.dept);
g_form.setReadOnly('iops_brm_department',true);
g_form.setVisable('iops_brm_department',true);
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2017 02:04 PM
I managed to find the solution. I was using an array for no good reason which complicated things. I removed the array and updated the script include.
Old, non-working, Script Include:
var getRequestedForData = Class.create();
getRequestedForData.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserData: function() {
try {
var userId = this.getParameter('sysparm_id');
var result = this.newItem('result');
var array = [];
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', this.getParameter('sysparm_id'));
while(gr.next()) {
var object = {};
object.id = gr.getUniqueValue();
object.loc = gr.getValue('location.name');
object.dept = gr.getValue('department.name');
array.push(object);
}
var json = new JSON();
var data = json.encode(array);
return data;
}
catch(e) {
gs.log("CDL: E- " + e.message);
}
},
type: 'getRequestedForData'
});
New, working, Script Include:
var getRequestedForData = Class.create();
getRequestedForData.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserData: function(name) {
var iopsSysId = this.getParameter('sysparm_id');
var gr = new GlideRecord('sys_user');
gr.addQuery("sys_id", iopsSysId);
gr.query();
if (gr.next()) {
var ga = {};
ga.id = gr.sys_id + '';
ga.loc = gr.location.name + '';
ga.dept = gr.department.name + '';
var json = new JSON();
ga = json.encode(ga);
return ga;
}
}
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2017 12:38 PM
You forgot to do gr.query() in your server side script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2017 03:29 PM
Good catch but still not updating after fixing it. Thanks for the catch though.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2017 05:33 AM
Change setVisable to setVisible too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2017 03:29 PM
Just like the other catch, Good catch but still not updating after fixing it. Thanks for the catch though.