None are not showing in dependent variable

keval3
Tera Contributor

Hi All,

There are 2 variable in serviceportal 1 Hr Category & Hr subcategory, HR subcategory are base on hr category, both are select box variable with None. but when I select category at that time HR subcategory will automatically populated  with out none it should be none. I have written below catalog client script. on change of category variable. 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    g_form.clearOptions('hr_subcategory');
    alert(g_form.getValue('hr_category'));

    var dependencies = {
        'Learning & Development (L&D)': [
            { value: 'User Creation/Deletion', label: 'User Creation/Deletion' },
            { value: 'Login issues', label: 'Login issues' },
            { value: 'reports', label: 'reports' },
        ],
        'Talent Management': [
            //{ value: 'none', label: 'none' },
            { value: 'User Creation/Deletion', label: 'User Creation/Deletion' },
            { value: 'Login issues', label: 'Login issues' },
            { value: 'reports', label: 'reports' },
            { value: 'Compliance course', label: 'Compliance course' },
            { value: 'Talent Review', label: 'Talent Review' },
            { value: 'Calibration', label: 'Calibration' },
            { value: 'Metrics Review', label: 'Metrics Review' },
            { value: 'Online courses', label: 'Online courses' }
        ],
        'Employee Data Management (EDM)': [
            //{ value: 'none', label: 'none' },
            { value: 'UGDN creation', label: 'UGDN creation' },
            { value: 'Position ID creation', label: 'Position ID creation' },
            { value: 'SAP ID creation', label: 'SAP ID creation' },
            { value: 'Transfer', label: 'Transfer' },
            { value: 'Promotion', label: 'Promotion' },
            { value: 'Termination', label: 'Termination' },
            { value: 'HR Letter', label: 'HR Letter' },
            { value: 'Reports', label: 'Reports' },
            { value: 'Personal Details Change', label: 'Personal Details Change' },
            { value: 'Work Details Change', label: 'Work Details Change' }
        ],
 
keval3_0-1736348646228.png

 

Thanks & Regards

KP

 

 

1 ACCEPTED SOLUTION

@keval3 

Assuming the choice values for the HR category in JSON are correctly configured and the choice labels and choice values in that json for sub category is correct configured

update script as this

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    g_form.clearOptions('hr_subcategory');
    alert(g_form.getValue('hr_category'));

    var dependencies = {
        'Learning & Development (L&D)': [{
                value: 'User Creation/Deletion',
                label: 'User Creation/Deletion'
            },
            {
                value: 'Login issues',
                label: 'Login issues'
            },
            {
                value: 'reports',
                label: 'reports'
            },
        ],
        'Talent Management': [
            //{ value: 'none', label: 'none' },
            {
                value: 'User Creation/Deletion',
                label: 'User Creation/Deletion'
            },
            {
                value: 'Login issues',
                label: 'Login issues'
            },
            {
                value: 'reports',
                label: 'reports'
            },
            {
                value: 'Compliance course',
                label: 'Compliance course'
            },
            {
                value: 'Talent Review',
                label: 'Talent Review'
            },
            {
                value: 'Calibration',
                label: 'Calibration'
            },
            {
                value: 'Metrics Review',
                label: 'Metrics Review'
            },
            {
                value: 'Online courses',
                label: 'Online courses'
            }
        ],
        'Employee Data Management (EDM)': [
            //{ value: 'none', label: 'none' },
            {
                value: 'UGDN creation',
                label: 'UGDN creation'
            },
            {
                value: 'Position ID creation',
                label: 'Position ID creation'
            },
            {
                value: 'SAP ID creation',
                label: 'SAP ID creation'
            },
            {
                value: 'Transfer',
                label: 'Transfer'
            },
            {
                value: 'Promotion',
                label: 'Promotion'
            },
            {
                value: 'Termination',
                label: 'Termination'
            },
            {
                value: 'HR Letter',
                label: 'HR Letter'
            },
            {
                value: 'Reports',
                label: 'Reports'
            },
            {
                value: 'Personal Details Change',
                label: 'Personal Details Change'
            },
            {
                value: 'Work Details Change',
                label: 'Work Details Change'
            }
        ]
    };

    // Add the "None" option
    // Add the "None" option
    g_form.addOption('hr_subcategory', '', '-- None --');

    // Populate the subcategories based on the selected category
    var selectedCategory = g_form.getValue('hr_category');
    if (dependencies[selectedCategory]) {
        dependencies[selectedCategory].forEach(function(subcategory) {
            g_form.addOption('hr_subcategory', subcategory.value, subcategory.label);
        });
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@keval3 

seems you didn't share the complete code

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@keval3 

Assuming the choice values for the HR category in JSON are correctly configured and the choice labels and choice values in that json for sub category is correct configured

update script as this

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    g_form.clearOptions('hr_subcategory');
    alert(g_form.getValue('hr_category'));

    var dependencies = {
        'Learning & Development (L&D)': [{
                value: 'User Creation/Deletion',
                label: 'User Creation/Deletion'
            },
            {
                value: 'Login issues',
                label: 'Login issues'
            },
            {
                value: 'reports',
                label: 'reports'
            },
        ],
        'Talent Management': [
            //{ value: 'none', label: 'none' },
            {
                value: 'User Creation/Deletion',
                label: 'User Creation/Deletion'
            },
            {
                value: 'Login issues',
                label: 'Login issues'
            },
            {
                value: 'reports',
                label: 'reports'
            },
            {
                value: 'Compliance course',
                label: 'Compliance course'
            },
            {
                value: 'Talent Review',
                label: 'Talent Review'
            },
            {
                value: 'Calibration',
                label: 'Calibration'
            },
            {
                value: 'Metrics Review',
                label: 'Metrics Review'
            },
            {
                value: 'Online courses',
                label: 'Online courses'
            }
        ],
        'Employee Data Management (EDM)': [
            //{ value: 'none', label: 'none' },
            {
                value: 'UGDN creation',
                label: 'UGDN creation'
            },
            {
                value: 'Position ID creation',
                label: 'Position ID creation'
            },
            {
                value: 'SAP ID creation',
                label: 'SAP ID creation'
            },
            {
                value: 'Transfer',
                label: 'Transfer'
            },
            {
                value: 'Promotion',
                label: 'Promotion'
            },
            {
                value: 'Termination',
                label: 'Termination'
            },
            {
                value: 'HR Letter',
                label: 'HR Letter'
            },
            {
                value: 'Reports',
                label: 'Reports'
            },
            {
                value: 'Personal Details Change',
                label: 'Personal Details Change'
            },
            {
                value: 'Work Details Change',
                label: 'Work Details Change'
            }
        ]
    };

    // Add the "None" option
    // Add the "None" option
    g_form.addOption('hr_subcategory', '', '-- None --');

    // Populate the subcategories based on the selected category
    var selectedCategory = g_form.getValue('hr_category');
    if (dependencies[selectedCategory]) {
        dependencies[selectedCategory].forEach(function(subcategory) {
            g_form.addOption('hr_subcategory', subcategory.value, subcategory.label);
        });
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    g_form.clearOptions('hr_subcategory');
    alert(g_form.getValue('hr_category'));

    var dependencies = {
        'Learning & Development (L&D)': [
            //{ value: 'none', label: 'none' },
            { value: 'User Creation/Deletion', label: 'User Creation/Deletion' },
            { value: 'Login issues', label: 'Login issues' },
            { value: 'reports', label: 'reports' },
            { value: 'Compliance course', label: 'Compliance course' },
            { value: 'LMS queries/E-Learning queries/L&D related queries', label: 'LMS queries/E-Learning queries/L&D related queries' },
            { value: 'Talent Review', label: 'Talent Review' },
            { value: 'Calibration', label: 'Calibration' },
            { value: 'Metrics Review', label: 'Metrics Review' },
            { value: 'Online courses', label: 'Online courses' }
        ],
        'Talent Management': [
            //{ value: 'none', label: 'none' },
            { value: 'User Creation/Deletion', label: 'User Creation/Deletion' },
            { value: 'Login issues', label: 'Login issues' },
            { value: 'reports', label: 'reports' },
            { value: 'Compliance course', label: 'Compliance course' },
            { value: 'LMS queries/E-Learning queries/L&D related queries', label: 'LMS queries/E-Learning queries/L&D related queries' },
            { value: 'Talent Review', label: 'Talent Review' },
            { value: 'Calibration', label: 'Calibration' },
            { value: 'Metrics Review', label: 'Metrics Review' },
            { value: 'Online courses', label: 'Online courses' }
        ],
        'Employee Data Management (EDM)': [
            //{ value: 'none', label: 'none' },
            { value: 'UGDN creation', label: 'UGDN creation' },
            { value: 'Position ID creation', label: 'Position ID creation' },
            { value: 'SAP ID creation', label: 'SAP ID creation' },
            { value: 'Transfer', label: 'Transfer' },
            { value: 'Promotion', label: 'Promotion' },
            { value: 'Termination', label: 'Termination' },
            { value: 'HR Letter', label: 'HR Letter' },
            { value: 'Reports', label: 'Reports' },
            { value: 'Personal Details Change', label: 'Personal Details Change' },
            { value: 'Work Details Change', label: 'Work Details Change' }
        ],

         'Onboarding & Induction': [
            //{ value: 'none', label: 'none' },
            { value: 'UGDN details', label: 'UGDN details' },
            { value: 'Documentation', label: 'Documentation' },
            { value: 'Asset Allocation', label: 'Asset Allocation' },
            { value: 'Accommodation & Travel', label: 'Accommodation & Travel' },
            { value: 'Catalyst', label: 'Catalyst' },
            { value: 'ESS & LMS Session', label: 'ESS & LMS Session' },
            { value: 'Asset Handover', label: 'Asset Handover' },
            { value: 'Induction queries', label: 'Induction queries' },
            { value: 'Appointment Letter', label: 'Appointment Letter' },
            { value: 'Reports', label: 'Reports' }
        ],
         'India Payroll': [
            //{ value: 'none', label: 'none' },
            { value: 'Processing Inputs', label: 'Processing Inputs' },
            { value: 'Payroll Processing', label: 'Payroll Processing' },
            { value: 'Salary reports', label: 'Salary reports' },
            { value: 'Reports - Validation and Auditing', label: 'Reports - Validation and Auditing' },
            { value: 'Compliance', label: 'Compliance' },
            { value: 'Seperation Process', label: 'Seperation Process' },
            { value: 'Queries', label: 'Queries' },
            { value: 'Zing HR', label: 'Zing HR' },
            { value: 'Perks', label: 'Perks' },
            { value: 'Income Tax', label: 'Income Tax' },
            { value: 'Account Update', label: 'Account Update' },
            { value: 'Payslip', label: 'Payslip' },
            { value: 'Form 16', label: 'Form 16' },
            { value: 'Reports', label: 'Reports' }
        ],
         'Recruitment': [
            //{ value: 'none', label: 'none' },
            { value: 'Open Positions', label: 'Open Positions' },
            { value: 'Referal queries', label: 'Referal queries' },
            { value: 'Candidate interview status', label: 'Candidate interview status' },
            { value: 'Candidate offer status', label: 'Candidate offer status' },
            { value: 'Reports', label: 'Reports' }
        ],
         'Performance Management (PMS)': [
            //{ value: 'none', label: 'none' },
            { value: 'Goal setting Activities', label: 'Goal setting Activities' },
            { value: 'Performance Review Activities', label: 'Performance Review Activities' },
            { value: 'Calibration and communication', label: 'Calibration and communication' },
            { value: 'Performance Improvement Plan', label: 'Performance Improvement Plan' },
            { value: 'Annual Pay Plan', label: 'Annual Pay Plan' },
            { value: 'PMS form routing', label: 'PMS form routing' },
            { value: 'PMS form deletion', label: 'PMS form deletion' },
            { value: 'Reports', label: 'Reports' }
        ],
         'Mediclaim/Superannuation/NPS/ PF/': [
            //{ value: 'none', label: 'none' },
            { value: 'E-Insurance Card', label: 'E-Insurance Card' },
            { value: 'Dependent addition/ deletion', label: 'Dependent addition/ deletion' },
            { value: 'Superannuation', label: 'Superannuation' },
            { value: 'NPS', label: 'NPS' },
            { value: 'Reports', label: 'Reports' },
            { value: 'Claim support', label: 'Claim support' },
            { value: 'PF correction/ queries', label: 'PF correction/ queries' },
            { value: 'Insurance (GPA/ Group Gratuity/ GTL)', label: 'Insurance (GPA/ Group Gratuity/ GTL)' },
            { value: 'Loan requests/ queries', label: 'Loan requests/ queries' }
        ],
         'Compensation & Benefits': [
            //{ value: 'none', label: 'none' },
            { value: 'Salary corrections', label: 'Salary corrections' }
        ],
         'Timesheet & Leave Management': [
            //{ value: 'none', label: 'none' },
            { value: 'Attendence regularisation', label: 'Attendence regularisation' },
            { value: 'Leave calculation', label: 'Leave calculation' },
            { value: 'Reports', label: 'Reports' },
            { value: 'Supervisor change request', label: 'Supervisor change request' }
        ]

    };

    if (dependencies.hasOwnProperty(newValue)) {
        var options = dependencies[newValue];
        for (var i = 0; i < options.length; i++) {
            g_form.addOption('hr_subcategory', options[i].value, options[i].label);
        }
    } else {
        g_form.addOption('hr_subcategory', '', '-- None --'); // Default if no match
    }
}