Script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2024 11:35 PM
Hi All,
I have a requirement to populate a set of value in a lookup select field 'Department' which is getting values from Department table based on the lookup select field 'Business Unit' which is getting values from Business Unit table.
My solution:
1. I wrote an onchange client script to get the Business unit value (getting sys id of the value).
2. Wrote a script include to first get the name of the Business unit from business_unit table (as I'm getting the sysId from client script) and then try to glide Department table to get the set of values associated with business unit selected by the user.
Script Include:
Client script:
Issue: I'm unable to get the array of values from the department table. Need help to correct the code.
Thanks,
Nipan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2024 12:28 AM
Hi @Nipan1 ,
there are lot of fixes in your script, can you please share the text format of scritp instead of image ?
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2024 12:34 AM - edited 06-10-2024 12:35 AM
Hi @Sohail Khilji ,
Thanks for the reply!
Below are the code after some edits, please check.
Script Include:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2024 12:49 AM - edited 06-10-2024 12:50 AM
try :
Script Include :
fetchDepartment: function() {
var BUValue = this.getParameter('sysparm_bu');
var departValue = [];
var business ='';
if (BUValue != '') {
var gBU = new GlideRecord('business_unit');
gBU.addQuery('sys_id', BUValue);
gBU.query();
if(gBU.next()){
business = gBU.getValue('name');
gs.log('business: '+ business);
}
var gDept = new GlideRecord('cmn_department');
gDept.addQuery('business_unit', BUValue);
gDept.query();
while (gDept.next()) {
departValue.push(gDept.getValue('name').toString());
}
}
return departValue;
},
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var bu = g_form.getValue('business_unit');
var ga = new GlideAjax("ProblemSBUUtils");
ga.addParam('sysparm_name', 'fetchDepartment');
ga.addParam('sysparm_bu', g_form.getValue('business_unit'));
ga.getXMLAnswer(getResponse);
function getResponse(response) {
var answer = response;
gs.addInfoMessage(answer);
}
}
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....