Need Help Returning Values with GlideAjax

codechaser
Giga Expert

I need to populate a dropdown of courses, based-on the term selected. I have a GlideAjax call to fetch the data and then use the addOption() function to populate the value in the 'u_course' field.   However, I am unable to filer courses offered by 'u_term_code'... The same list of courses is populated, regardless of term selected.

What am I missing?

Grade_Change_Form.png

Client Script:

function onChange(control, oldValue, newValue, isLoading) {

if (isLoading || newValue == '') {

return;    

}  

var ga = new GlideAjax('GetListValue');

ga.addParam('sysparm_name','getList');

ga.addParam('sysparm_term ', newValue);

ga.getXML(fillDetails);

function fillDetails(serverResponse){

var answer = serverResponse.responseXML.documentElement.getAttribute("answer");

var choiceval = answer.split(',');

for(var i = 0; choiceval.length > i ; i++){

g_form.addOption('u_course', choiceval[i], choiceval[i], [i]);

}

}

}

Client Callable Script Include:

var GetListValue = Class.create();

GetListValue.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getList : function() {

var courses = [];

var gr = new GlideRecord('u_bsu_courses');

gr.addQuery('u_term_code', this.getParameter('sysparm_term'));

gr.query();

while(gr.next())

courses.push(gr.name.toString());

return courses;

},

type: 'GetListValue'

});

12 REPLIES 12

Ok, so the line should read: ga.addParam('sysparm_term ', g_form.getValue('u_term_code'));


and this is an onChange, so you're testing by changing the Term Code?



In the script includes, add:


var term = this.getParameter(''sysparm_term');


gs.log('Term is ='+ term);


does it return the correct value?



Put a gs.log after the while in the script includes - what's being returned?


and BTW - you're Course field isn't dependent on Term field, correct? It's just a choice field with choices.


Sorry for the confusion, but just want to double-check putting a gs.log after var term = this.getParameter('sysparm_term'); and after while on the script include, correct?   Course field is not dependent on Term, but guessing it should be if we are trying to refine our results, based-on the term courses are offered in?


Yes on the gs.log lines.



Making Course dependent on Term would probably forgo all of this code!


I agree 100% Michael!   However, when I right-click the field label to configure dictionary, there is no place to add a dependent field.   Is there another setting somewhere, perhaps I am missing?