Catalog task resolver input variable mandatory

SumajRajNk
Tera Contributor

There are 2 task resolver input variables that I want in my catalog task. Both should be mandatory, and 2nd resolver variable is dependent on 1st variable answer When 'Yes'. I want to hide these resolver input variables in RITM view and Catalog item view and make it visible in task and only when we try to change the state of task to 'Closed Complete' not when it is in 'Open' State . Please help me in Solving this as I am new to Servicenow.

 

Solutions to the query is highly appreciated !

#task #resolvervariable #catalogitem

2 REPLIES 2

KKM
Tera Guru

Hi SumajRaj,
To achieve this in ServiceNow, follow these steps:

1. Make Resolver Variables Mandatory & Dependent
Go to Maintain Items (sc_cat_item) and open your catalog item.
Under the Variables tab, create two variables:
First Variable (e.g., resolver_var_1)
Type: Yes/No
Mandatory: Yes
Second Variable (e.g., resolver_var_2)
Type: Any suitable type
Mandatory: Yes
Create a UI Policy:
Condition: resolver_var_1 == Yes
Action: Show resolver_var_2
2. Hide Variables in RITM & Catalog Item View
Use UI Policies or Client Scripts:
Create a UI Policy for each variable:
Condition: true (Always applies)
Actions:
RITM View (sc_req_item): Set visibility to false
Catalog Item View (sc_cat_item): Set visibility to false
OR, use a Client Script:

if (g_form.getTableName() == 'sc_req_item' || g_form.getTableName() == 'sc_cat_item') {
g_form.setDisplay('resolver_var_1', false);
g_form.setDisplay('resolver_var_2', false);
}
3. Show Variables Only in Task When Closing
Create a UI Policy for the Task (sc_task) form:
Condition: State == Closed Complete
Actions:
resolver_var_1: Set visibility to true
resolver_var_2: Set visibility to true
Add a reverse action for when the task is in Open State:
Set visibility to false
Alternatively, use a Client Script:

(function executeRule(current, gForm, gSNC) {
var state = current.state;

if (state == '3') { // 'Closed Complete' state
gForm.setDisplay('resolver_var_1', true);
gForm.setDisplay('resolver_var_2', true);
} else {
gForm.setDisplay('resolver_var_1', false);
gForm.setDisplay('resolver_var_2', false);
}
})(current, gForm, gSNC);
Replace 3 with the correct state value for Closed Complete in your instance.

Final Check
* Variables are mandatory.
* resolver_var_2 appears only when resolver_var_1 == Yes.
* Variables are hidden in RITM and Catalog views.
* Variables show in the Task only when changing the state to Closed Complete.

This should solve your issue!

Kindly mark it as "Accepted Solution"/"helpful", as it resolves your query. Please press like button for the resolution provided.

With Regards,
Krishna Kumar M - Talk with AIT3ch
LinkedIn: https://www.linkedin.com/in/mkrishnak4/
YouTube: https://www.youtube.com/@KrishAIT3CH
Topmate: https://topmate.io/mkrishnak4 [ Connect for 1-1 Session]

Ankur Bawiskar
Tera Patron
Tera Patron

@SumajRajNk 

I assume you can write catalog UI policy which applies on Catalog view and RITM view and then hide the 2 variables.

so you can have normal onChange client script on sc_task table and not catalog client script and if state is closed complete then check variable value

If both are empty then make those variables as mandatory

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    if (newValue.toString() == '3') {
        var variable1Value = g_form.getValue('variables.variableA');
        var variable2Value = g_form.getValue('variables.variableB');
        if (variable1Value != '' && variable2Value != '') {
            // all good
        } else {
            g_form.addErrorMessage('Both the variables are to be filled');
            g_form.setMandatory('variables.variableA', true);
            g_form.setMandatory('variables.variableB', true);
        }
    }

}

If you want you can have onSubmit script as well on sc_task

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