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-02-2023 08:55 PM - edited 03-02-2023 09:01 PM
Hi @Community Alums
Do you mean to filter the dropdown values of Country field based on the value selected in Business unit?
If yes, I would suggest to use scripted Reference qualifier on Country field.
Or if you need the options needs to be altered only in this case, you can use g_form.addOption(fieldName,choiceValue,choiceLabel,choiceIndex)
Please mark this helpful, if it answers your question.
Thanks
Fazal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2023 09:01 PM - edited 03-02-2023 09:02 PM
Hi @Fazal Mohammad ,
The values I have highlighted which is the correct response I am getting from script include. Those values need to be populated in dropdown.
I tried reference qualifier but unfortunately it is not working
Script include I tried
country: function(a) {
gs.info("I am Business" + a);
var gr = new GlideAggregate('u_oracle_financial_approvals');
gr.addQuery('u_business_unit', a);
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;
},
and reference qualifier
javascript: new oracle_bu().country(current.variables.u_business_unit)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2023 09:09 PM
Hi @Community Alums
Please give the reference qual as below:
javascript:'sys_idIN'+(new oracle_bu()).country(current);
and in script include, country method just return a string which has comma separated sys_ids of Country example ("sys_id1,sys_id2,sys_id3");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2023 09:21 PM
Hi @Fazal Mohammad ,
I copied the below line in reference qualifier
javascript:'sys_idIN'+(new oracle_bu()).country(current);
Can you please what changes I should make in below script -
country: function(a) {
gs.info("I am Business" + a);
var gr = new GlideAggregate('u_oracle_financial_approvals');
gr.addQuery('u_business_unit', a);
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.info('Final Result', data);
return data;
},