How to print data received from script include in Dropdown

Community Alums
Not applicable

Hello All,

 

We have two fields on the form, and referring to same table

1) Business Unit - Lookup Select Box

2) Country - Lookup Select Box

 

I have written below scripts 

Script include - 

country: function() {
var bu = this.getParameter('sysparm_bu');
gs.log("I am Business" + bu);
//var arr = [];
var gr = new GlideAggregate('u_oracle_financial_approvals');
gr.addQuery('u_business_unit', bu);
gr.groupBy('u_country');
gr.query();
gs.log("Tejas" + gr);

var arr = [];
while (gr.next()) {
var obj = gr.getValue('u_country').toString()+"";
arr.push(obj);
gs.log("Result", +arr);

}
var data = JSON.stringify(arr);
gs.log('Final Result', data);
return data;
},

 

OnChange Catalog Client Script - 


var rf = g_form.getDisplayValue('u_business_unit');
alert('Hi, I am ' + rf);
var ga = new GlideAjax('Oracle_Business_Units');
ga.addParam('sysparm_name', 'country');
alert('Hi, I am ' + rf);
ga.addParam('sysparm_bu', rf);
ga.getXMLAnswer(setAnswer);

function setAnswer(response) {
var arr = JSON.parse(response);
//var res = arr.split('#');
g_form.setValue('country', arr);

}

 

We are getting output in below format

Tejas12_0-1677818491094.png

 

Issue - We want highlighted data to be printed as dropdown values and remove the above values which are populating from table.

 

Please help!

 

Thanks,

Tejas

 

 

20 REPLIES 20

Hi @Community Alums 

 

Please update with below code

 

country: function(current) {

gs.info("I am Business" + current.variables.u_business_unit);

var gr = new GlideAggregate('u_oracle_financial_approvals');
gr.addQuery('u_business_unit', current.variables.u_business_unit);
gr.groupBy('u_country');
gr.query();
gs.log("Tejas" + gr);

var arr = [];
while (gr.next()) {
var obj = gr.getValue('u_country').toString()+" ";
arr.push(obj);
gs.log("Result", +arr);

}
var data = arr.join();
gs.info('Final Result', data);
return data;
},

 

Community Alums
Not applicable

Hi @Fazal Mohammad ,

 

I tried the above script as well

In final result log getting below output - 

Tejas12_0-1677822487551.png

 

and In Country field "No matches found"

Community Alums
Not applicable

Hi @Fazal Mohammad ,

Am I making any mistakes in field configuration

Tejas12_1-1677822753703.png

 

Community Alums
Not applicable

@SumanthDosapati 

Could you please help me here?

@Community Alums What is the output of below code?

gs.info("I am Business" + current.variables.u_business_unit);