Return a JSON string in a form drop-down

appstorm
Tera Contributor

I have an SI to populate a JSON string in a drop-down.  However, I am unsure where and how to code the input for the variable string.

 

SI

var Test = Class.create();

Test.prototype = Object.extendsObject(AbstractAjaxProcessor, {

 CourseUtils: function()

   {

   try {

   var r = new sn_ws.RESTMessageV2('Banner Courses', 'get');

   var response = r.execute();

   var responseBody = response.getBody();

   var httpStatus = response.getStatusCode();

   return responseBody;

   }

   catch(ex) {

   var message = ex.getMessage();

   return "";

   }

   },

       type: 'Test'

});

 

CS

 

1 ACCEPTED SOLUTION

@appstorm mark it as accepted as solution and helpful if it works

View solution in original post

5 REPLIES 5

Brad Bowman
Kilo Patron
Kilo Patron

Looks like your Client Script didn't post.  What is an example of the expected responseBody you are passing to the client?

{"TERM_DESC":"Fall 2024","SUBJ_CODE":"SOCI","CRSE_NUMB":"245","SEQ_NUMB":"50P","INSTRUCTOR":" "},

 

Also, here is my CS:

function onLoad() {

     //Type appropriate comment here, and begin script below

var ga = new GlideAjax('Test');

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

ga.getXML(CourseUtilsOutput);

} 

function CourseUtilsOutput(response) {

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

   alert(answer);

     var objJSON = JSON.parse(answer);

   for(var loop = 0 ; loop < objJSON.courses.length;loop++)

   {

   /*alert(objJSON.courses[loop].Name);

   g_form.addOption('course_information',objJSON.courses[loop].Value,objJSON.courses[loop].Name);*/

   }

}

@appstorm ok in for loop

 sample code

 

 for (var i = 0; i < objJSON.courses.length; i++) {
var choice=objJSON.courses[i];
                g_form.addOption('course_information',  choice.SUBJ_CODE + ' ' +  choice.CRSE_NUMB+' '+  choice.SEQ_NUMB, choice.TERM_DESC);
            }

 

 

appstorm
Tera Contributor

Thank you for this - exactly what I was looking for.  I'm still getting a Unhandled exception in GlideAjax console error.  I'll have to work on decoding that and see where the problem(s) exist.