Script Include choices

Rajesh Annepak1
Kilo Guru

Hello All,

var dept_list = [];

  var str;

  var bu = new GlideRecord('u_salesforce_access');

  bu.addQuery('u_division',div);

  bu.query();

  while (bu.next()){

  uniqueMembers.push(bu.u_bu.toString());

  }

  var arrayUtil = new ArrayUtil();

  dept_list = arrayUtil.unique(uniqueMembers);

i have the dept_list values correct and displaying in   log as

find_real_file.png

I need to return these choices to the client script GlideAjax and from the client script i need to populate each option as a dropdown for select box data type in our catalog item

Could you please help me with the code to return these choices to client script and make it populate for a drop down field

Rajesh

1 ACCEPTED SOLUTION

Midhun1
Giga Guru

Hi rajesh,



Use   toString() while pushing to array it works.


View solution in original post

11 REPLIES 11

BALAJI40
Mega Sage

Make a for loop and use the addOption sysntax to achivee this one.



call the ajax call script,


var ga = new GlideAjax('script include name');


ga.addParam('sysparm_name','script include function name');


ga.getXML(choices);



function choices(response) {


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


  for (var i =0; i<answer.length:i++){


g_form.addOption('fieldname',answer [i],answer[i]);


}


}


Midhun1
Giga Guru

Hi Rajesh,



Have you used   return in   the function .   Use return dept_list.


Hello All,



I have used return funtion also , but i was getting an error like messgae


find_real_file.png



I think its not returning the correct value because dept_list is an array decalaration , so iam not able to fetch the options from the client side



I need how to return the options , Iam using an array in my script but that's not working



my question is how do i return the options to client side


Try this function,



var dept_list = [];


  var str;


  var bu = new GlideRecord('u_salesforce_access');


  bu.addQuery('u_division',div);


  bu.query();


  while (bu.next()){


  dept_list .push(bu.u_bu.toString());


  }


  var arrayUtil = new ArrayUtil();


  dept_list = arrayUtil.unique(dept_list .toString());


return dept_list;