- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2025 05:04 AM
We have a variable set named "tasks", and all variables within this set are currently marked as mandatory. This variable set is only displayed in the variable editor section of the sc_task form.
Now, the requirement is:
The variables in the "tasks" variable set should only be mandatory when the state field on the sc_task form is set to Closed Complete.
How can we implement this logic effectively, state is a field on the sc_task table and not part of the variable set?
For example we have variable - How many tasks required?
Options- 1. One Task, 2. Two tasks, 3. Three tasks.
If user select one task, assignment group one get visible
if user select two tasks , assignment group one and assignment group two get visible
I tried with standard onChange Client script on state field,
Script-
I selected state as closed complete and not saved yet the form and now when I'm trying to change - "How many task required" variable field-
Old value - one task and new value - two tasks,
It's not making mandatory for two tasks as shown in SS
IK that we are creating onChange script on state field but how to achieve our goal?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2025 10:54 AM
You have to check the values of the fields in the onSubmit and then return false if you don't want to save it. It would look something like this:
function onSubmit() {
var retval = true;
if (g_form.getValue('state') >= 3) { //Closing task
if (g_form.getValue(fieldToCheck) == '' ) {//add all your required fields here
retval = false;
}
return retval;
}
}
If you want to actually mark them all as required, you can do that in your onChange script or you can do it in the onSubmit. However, the thing that will stop it from being submitted is you checking the values and returning false if they are blank.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2025 05:13 AM
Did you try your client script as an onSubmit catalog client script off of the Catalog Item itself? You should be able to do that and just select for it to run on Catalog Tasks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2025 05:23 AM
Would you mind closing your earlier questions by marking appropriate response as correct?
Members have invested their time and efforts in helping you.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2025 06:47 AM
Please check.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2025 06:59 AM
Please check my below response.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader