- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2025 12:36 PM - edited ‎07-24-2025 12:58 PM
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?
I tried with standard UI policy, but it is making whole variable set mandatory as we have variables visibility on conditions.
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
But Using this UI policy all variables are visible on form load.
Script-
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2025 11:36 PM
2 ways
1) normal onChange client script on state field of sc_task and check if state is closed complete then make those mandatory
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue == '3') {
g_form.setMandatory('variables.variableName1', true);
g_form.setMandatory('variables.variableName2', true);
g_form.setMandatory('variables.variableName3', true);
}
}
2) You need to ensure this is handled via the OOTB Close Task UI action as well
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 02:52 AM
for your further requirement you cannot determine the old value or new value of variable in normal onchange client script on state field.
To access old value and new value you will have to use onChange catalog client script on that variable only.
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