Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Michael Fry1
Kilo Patron

Looks similar to a subcategory field where Term is the category. Are you getting a response now?



This like doesn't look right: for(var i = 0; choiceval.length > i ; i++){


Try this: for(var i = 0; i < subcats.length; i++) {


Hi Michael and thank you for the reply.   I made the change you suggested, above and am still returning all courses, no matter which term is selected.


Ok, try changing this line:


ga.addParam('sysparm_term ', newValue);



to


ga.addParam('sysparm_term ', g_form.getValue('u_term'));


where u_term is the name of your field.


Thank you for the suggestion.   Unfortunately, that did not work, either.   I also tried ga.addParam('sysparm_term ', 'u_term_code'); with no result.