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

Hi Midhun i havea similar problem.

its showing org.mozilla.javascriptnative in the drop down.

Script include code:

var GetLocationDetails = Class.create();
GetLocationDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCityValues: function(s1) {
var arr = [];
if (s1.nil()) {
return arr;
}
var count = new GlideAggregate('cmn_location');
count.addAggregate('COUNT', 'city');
count.orderByAggregate('COUNT', 'city', true);
count.addQuery('state', s1);
count.addActiveQuery();
count.query();
while (count.next()) {
arr.push(count.city.toString());
}
return arr;
},
getStateValues: function(c1) {
var arr = [];
if (c1.nil()) {
return arr;
}
gs.log("GetLOcationDetails" + c1);
var count = new GlideAggregate('cmn_location');
count.addAggregate('COUNT', 'state');
count.orderByAggregate('COUNT', 'state', true);
count.addQuery('country', c1);
count.addActiveQuery();
count.query();
while (count.next()) {
arr.push(count.state.toString());
}
gs.log("GetLOcationDetails" + arr);
return arr;
},

 

And client side code is :(for onload)

var getUserAddress = new GlideAjax('GetLocationDetails');
getUserAddress.addParam('sysparm_name', 'getStateValues');
getUserAddress.addParam('sysparm_sysid', g_form.getValue('country'));
getUserAddress.getXML(populateUserDetails);

function populateUserDetails(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.clearOptions('state_or_provience');
for (var i =0; i<answer.length;i++){
g_form.addOption('state_or_provience',answer[i],answer[i]);
}
}

can you please point out my error.Any help is appreciated!

Aindrila Mondal
Tera Expert

sorry pasted the wrong code

script include:

var GetLocationDetails = Class.create();
GetLocationDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCityValues: function() {
var s1=this.getParameter('sysparm_state_name');
var arr = [];
if (s1.nil()) {
return arr;
}
gs.log("GetLOcationDetails" + s1);
var count = new GlideAggregate('cmn_location');
count.addAggregate('COUNT', 'city');
count.orderByAggregate('COUNT', 'city', true);
count.addQuery('state', s1);
count.addActiveQuery();
count.query();
while (count.next()) {
arr.push(count.city);
}
return JSON.stringify(arr);
},
getStateValues: function() {
var c1=this.getParameter('sysparm_country_name');
var arr = [];
if (c1.nil()) {
return arr;
}
gs.log("GetLOcationDetails" + c1);
var count = new GlideAggregate('cmn_location');
count.addAggregate('COUNT', 'state');
count.orderByAggregate('COUNT', 'state', true);
count.addQuery('country', c1);
count.addActiveQuery();
count.query();
while (count.next()) {
arr.push(count.state);
}
gs.log("GetLOcationDetails" + arr);
return JSON.stringify(arr);
},

type: 'GetLocationDetails'
});

 

clients side:

var getUserAddress = new GlideAjax('GetLocationDetails');
getUserAddress.addParam('sysparm_name', 'getStateValues');
getUserAddress.addParam('sysparm_country_name, g_form.getValue('country'));
getUserAddress.getXML(populateUserDetails);

function populateUserDetails(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.clearOptions('state_or_provience');
for (var i =0; i<answer.length;i++){
g_form.addOption('state_or_provience',answer[i],answer[i]);
}
}