- 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:33 AM - edited 07-29-2025 05:44 AM
you can access form field value using g_form.getValue('state') in your Catalog client script
Then create your logic
If my response helped please mark it correct and close the thread so that it benefits future readers.
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 09:47 AM
Hi @JenniferRah , @Ankur Bawiskar
Tried below onChange catalog client script but not working.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2025 09:55 AM
You need to make it an onSubmit client script and make sure the "Applies on Catalog Tasks" is checked.
If it still isn't working, then I would need to know if you're running it from a client or Portal or both. Also, what specifically isn't working?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2025 10:33 AM
Hi @JenniferRah
Created onSubmit client script. But form is getting saved even if fields are empty when state is closed complete.
Script-

- 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.