I am looking for script for my condition.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2024 01:23 AM
I am looking for script for my condition in script include. I have two variables that refers to customised table- first variable consider 'A' refers to customised table where Active = true. In second VARIABLE 'B' also refers to same customised table & it should display the Super Business unit of the selected region from the varaible 'A' of the customised table.
Considering all the business unit number of Variable -'A' it should display all the super business unit in the variable - 'B'.
- Labels:
-
Data Foundations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2024 01:50 AM
Hi @Taaha M ,
As its a custom table and fields, we don't have much insights into it.
To your question you need 2 things-
1. a script include that will fetch and filter data based on the selected values of your custom fields from the form.
2. onChange client script for the FAST region variable to call the script include and populate the FAST office name variable
Here’s a generic script include and client script that you can use-
Script include-
var CustomTableHelper = Class.create();
CustomTableHelper.prototype = {
initialize: function() {},
getSuperBusinessUnits: function(selectedRegion) {
var result = [];
// Query the custom table for active records matching the selected region
var customTableGR = new GlideRecord('x_custom_table');
customTableGR.addQuery('active', true);
customTableGR.addQuery('region', selectedRegion);
customTableGR.query();
while (customTableGR.next()) {
result.push(customTableGR.super_business_unit.toString());
}
return result;
}
};
Client script-
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('CustomTableHelper');
ga.addParam('sysparm_name', 'getSuperBusinessUnits');
ga.addParam('sysparm_selectedRegion', newValue);
ga.getXMLAnswer(function(response) {
var superBusinessUnits = JSON.parse(response);
g_form.clearOptions('fast_office_name'); // clear existing options
g_form.addOption('fast_office_name', '', '--Select--');//default
// Populate the options with super business units
superBusinessUnits.forEach(function(unit) {
g_form.addOption('fast_office_name', unit, unit);
});
});
}
The above should be the logic to implement the required solution.
Note- You need update the correct data in the above scripts as per your instance. Table info, fields info also the data that will flow.
If my response has resolved your query, please consider giving it a thumbs up ‌‌ and marking it as the correct answer‌‌!
Thanks & Regards,
Sanjay Kumar