Checking checkbox before closing task

Hafila Hatta
Tera Guru

hi. i have a list of checkbox below being displayed in Sc_TASK. how do i make a checking to ensure that all checkbox are checked before closing the task?

 

Note: the checkbox are variable set

 

HafilaHatta_0-1744077592415.png

 

14 REPLIES 14

Ankur Bawiskar
Tera Patron
Tera Patron

@Hafila Hatta 

you can use onSubmit normal client script on sc_task and check the variable value

function onSubmit() {
    if (g_form.getValue('state').toString() == '3') {
        // give the checkbox variable names here
        var checkboxes = ['checkbox1', 'checkbox2', 'checkbox3', 'checkbox4', 'checkbox5', 'checkbox6'];
        var allChecked = true;

        checkboxes.forEach(function(checkbox) {
            if (g_form.getValue('variables.' + checkbox).toString() != 'true') {
                allChecked = false;
            }
        });

        if (!allChecked) {
            g_form.addErrorMessage('All checkboxes should be checked during closure');
            return false;
        }
    }
}

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

thanks, how do i ensure it only run for the specific task?

@Hafila Hatta 

you can check specific catalog task short description

function onSubmit() {
    if (g_form.getValue('state').toString() == '3' && g_form.getValue('short_description') == 'your catalog task short description') {
        // give the checkbox variable names here
        var checkboxes = ['checkbox1', 'checkbox2', 'checkbox3', 'checkbox4', 'checkbox5', 'checkbox6'];
        var allChecked = true;

        checkboxes.forEach(function(checkbox) {
            if (g_form.getValue('variables.' + checkbox).toString() != 'true') {
                allChecked = false;
            }
        });

        if (!allChecked) {
            g_form.addErrorMessage('All checkboxes should be checked during closure');
            return false;
        }
    }
}

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

@Hafila Hatta 

Did this work for you?

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

@Hafila Hatta 

Hope you are doing good.

Did my reply answer your question?

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