UI Policy to select specific variable options on closure of sc_task

Cat
Mega Guru

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!

1 ACCEPTED SOLUTION

Cat
Mega Guru

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

View solution in original post

3 REPLIES 3

Jon23
Mega Sage

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

Ankur Bawiskar
Tera Patron
Tera Patron

@Cat 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Cat
Mega Guru

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