How to print data received from script include in Dropdown

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2023 08:43 PM
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
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2023 03:07 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2023 11:07 PM
Hi @Community Alums
Looks like there are more than 1 issue in the script. Check below points once:
1) In OnChange Client script you are passing the word country as string.
2) Check the format of data you are passing in script include and receiving in client script.
Regards,
Sumanth

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2023 02:34 AM - edited 03-06-2023 02:37 AM
Hi @SumanthDosapati,
Thanks for your reply. Please help me here.
That 'country' is function name we are sending value to script include.
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);
}
With above scripts we are getting below output where we don't need highlighted country names which are coming from reference table, we need those highlighted in blue which is correct output getting added at the end with comma separated values
Thanks,
Tejas

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2023 02:49 AM
Hi @SumanthDosapati ,
With the above script I am getting expected output in logs
but in the variable on the form I am getting all country values with my expected values with printed in one line as comma separated values (As I attached SS in previous reply), which need to be choices
Thanks,
Tejas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2023 06:56 AM
@Community Alums just for testing, Can you please comment the below code?
gr.addQuery('u_business_unit', current.variables.u_business_unit);
and check once? Is it returning all the country records?