Problems with onLoad()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 11:52 AM
so, I have these fields:
What I'm trying to do is create a client Script so that, depending on the option chosen in the 'Area' field, only show certain options in the 'Type' field, However, I'm not succeeding, I'm trying to create an onLoad() code
function onLoad() {
var areaValue = g_form.getValue('area');
var typeField = g_form.getControl('type');
// Clear all options from the 'Type' field
typeField.innerHTML = '';
// Define the allowed options for each area
var allowedOptions = [];
if (areaValue === 'ti') {
allowedOptions = ['Backup and Recovery', 'Configuration', 'Consulting', 'Customization', 'Installation', 'Maintenance', 'Request'];
} else if (areaValue === 'seg') {
allowedOptions = ['Backup and Recovery', 'Configuration', 'Consulting', 'Customization', 'Installation', 'Maintenance'];
}
// Add the allowed options to the 'Type' field
for (var i = 0; i < allowedOptions.length; i++) {
var option = allowedOptions[i];
typeField.add(new Option(option, i));
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2024 04:32 PM
Hi, unfortunately your post doesn't provide any clear details of the issue you have encountered?
What are the results of your script debugging? does your code work as expected?
Can you share details of your code source, is it from a community post or article?
Have you tried using removeOption()
GlideForm | ServiceNow Developers
Also, I expect that if area can be changed from the form, you would also need to replicate your code in an onChange script?