Problems with onLoad()

Arthur Sanchez
Giga Guru

so, I have these fields:
Captura de tela 2024-05-16 154737.pngCaptura de tela 2024-05-16 154826.pngCaptura de tela 2024-05-16 154833.png

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));
    }
}

 

 

1 REPLY 1

Tony Chatfield1
Kilo Patron

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?