- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 02:05 AM
Hi All,
I'm looking to create a System UI Policy, where they have to choose one of 3 from a number of variable options to close the task.
For example, there are 10 options within the variable next_steps but they want any one of 3 of them to be selected before the task can be closed.
I'm thinking UI policy, and I'm aware of set mandatory, but I don't know how to say that when there are specific mandatory options, not just that anything is selected.
This is only to affect one catalog item.
The existing script requires resolution notes to be filled in before closure - this works as expected:
function onCondition() {
g_form.setMandatory('variables.resolution_notes',true);
}
I hope this makes sense. Any help would be appreciated!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2024 02:00 AM
Thanks both, I ended up doing the following as an onSubmit Catalog Client Script:
function onSubmit() {
var taskState = g_form.getValue('state');
var varStatus = g_form.getValue('status');
if (taskState >= 3) {
if (!(varStatus == 'resolved' || varStatus == 'closed_pending_release' || varStatus == 'Cancelled/Declined')) {
g_form.clearValue('state'); // Clear the state field
g_form.showFieldMsg('state', 'To close the task, please set a status of Resolved, Closed pending release, or Cancelled/Declined.', 'error'); // Display error message
return false; // Prevent form submission
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 04:01 PM
Hi @Cat ,
I would consider updating the choice list so it only displays the acceptable 3 values, and make it mandatory. I'm guessing you can add the code to your existing resolution_notes script you referenced.
Check out SNGuru: Removing or Disabling Choice List Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 07:19 PM
you can use normal onChange client script on sc_task and handle this
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
var val = g_form.getValue('variables.next_step');
if (newValue == "3" && (val == 'val1' || val == 'val2' || val == 'val3')) {
g_form.setMandatory('variables.resolution_notes', true);
} else {
g_form.setMandatory('variables.resolution_notes', false);
}
}
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
12-17-2024 02:00 AM
Thanks both, I ended up doing the following as an onSubmit Catalog Client Script:
function onSubmit() {
var taskState = g_form.getValue('state');
var varStatus = g_form.getValue('status');
if (taskState >= 3) {
if (!(varStatus == 'resolved' || varStatus == 'closed_pending_release' || varStatus == 'Cancelled/Declined')) {
g_form.clearValue('state'); // Clear the state field
g_form.showFieldMsg('state', 'To close the task, please set a status of Resolved, Closed pending release, or Cancelled/Declined.', 'error'); // Display error message
return false; // Prevent form submission
}
}
}