add the select box value dynamically
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 03:03 AM
Hi All,
I am trying to add the value dynamically in the select box for one of the group of users by using below catalog client script...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 04:19 AM
Hi @VaibhavJ ,
Try using below code.
function onLoad() {
var selectBox = g_form.getControl('what_is_this_request_for');
if (selectBox) {
// Clear existing options
selectBox.options.length = 0;
// Call GlideAjax to check if the user is in the group
var Compuser = new GlideAjax('InteractionUtils');
Compuser.addParam('sysparm_name', 'isUserInCorporate_Compensation_Group');
Compuser.getXML(function(response) {
var isInGroup = response.responseXML.documentElement.getAttribute('answer');
// Define options based on group membership
var groupOptions = [
{ value: 'job_codes', label: 'Job Codes' },
{ value: 'job_families', label: 'Job Families' },
{ value: 'job_functions', label: 'Job Functions' }
];
var defaultOptions = [
{ value: 'license_certification', label: 'License or Certification' },
{ value: 'earnings_codes', label: 'Earnings Codes' },
{ value: 'deduction_codes', label: 'Deduction Codes' },
{ value: 'tax_codes', label: 'Tax Codes' }
];
// Add options to the select box
var optionsToAdd = isInGroup === 'true' ? groupOptions.concat(defaultOptions) : defaultOptions;
optionsToAdd.forEach(function(option) {
selectBox.add(new Option(option.label, option.value));
});
});
}
}
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------