Checking checkbox before closing task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2025 07:00 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2025 09:11 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2025 09:40 PM
@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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2025 10:00 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2025 11:08 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2025 10:20 AM
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;
}