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

But @Hafila Hatta 

 

This won't work when you are changing the value. Because "On submit" client script is not having "newValue" on the form, it's only having the "oldValue" - so when you change the state to closed-complete or skipped. It won't be detected. Because On-submit doesn't have the current value. there is a reason servicenow gave us on change and on submit client script - there is difference between what both can offer and limits. 

 

This is basic technical deterrance here. That's the reason I thought of on submit client script but didn't recommend that. 

 

And newValue - means current value of state can be obtained via on change client script @Hafila Hatta but the thing is it will not deter the submitance of form. 

 

I hope you understand these technical deterrance in client scripts. Business rule is the best way to go here and that will only work, you can try this out but it won't work. Technically this is how it works. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

@Shivalika 

@Hafila Hatta simply wants the checkbox to be checked, so no dependency on old or new value etc.

The client script should work fine as I have worked on something similar recently and it works

The script simply checks if the checkbox is true or not.

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

@Ankur Bawiskar 

 

There is dependency on state value. Hello doesn't simply wants for checkbox. So there is old and new value of state field. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

@Shivalika 

It should work for @Hafila Hatta

It would be great to hear the feedback from the person who asked the question.

As per knowledge this requirement is achievable using onSubmit client script.

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

Ian Mildon
Tera Guru

You can also do variations on the suggested script (which is similar to mine) where you can set a specific number of required checkboxes to be checked as in this example where I have the "mandatoryCount" set to 1

function onSubmit() {
    //Set the mandatory checkbox variable names and total mandatory count here

    var mandatoryVars = 'care_gap,ecqm,hedis,other';
    var mandatoryCount = 1;

    var passed = forceMandatoryCheckboxes(mandatoryVars, mandatoryCount);
    if (!passed) {
        setHighlight();
        //Abort the submit
        alert("You must check at least " + mandatoryCount + " of the 'Needed For' checkboxes on this form.");
        return false;
    }
}

function forceMandatoryCheckboxes(mandatory, count) {
    //Split the mandatory variable names into an array
    mandatory = mandatory.split(',');
    var answer = false;
    var varFound = false;
    var numTrue = 0;
    //Check each variable in the array
    for (x = 0; x < mandatory.length; x++) {
        //Check to see if variable exists
        if (g_form.getControl(mandatory[x])) {
            varFound = true;
            //Check to see if variable is set to 'true'
            if (g_form.getValue(mandatory[x]) == 'true') {
                numTrue++;
                //Exit the loop if we have reached required number of 'true'
                if (numTrue >= count) {
                    answer = true;
                    break;
                }
            }
        }
    }
    //If we didn't find any of the variables allow the submit
    if (varFound == false) {
        answer = true;
    }
    //Return true or false
    return answer;
}