Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to make variable set field mandatory in catalog item

SNDP
Tera Contributor

I have a variable set which I am using in various catalog items, in the variable set contains multiple check boxes . I need to make the variable set mandatory in all catalog items that is atleast one check box is mandatory to submit the form, when I try to make the variable set mandatory from UI policy for a single catalog item, it makes all the check boxes mandatory in the form.Anyway I can achieve this?

1 ACCEPTED SOLUTION

Prashant Ahire
Kilo Sage

Hello @SNDP 

You use this onSubmit Client script on variable set - 

I have Trial and Tested in my Instance

 

function onSubmit() {
    var value1 = g_form.getValue('check_box_1'); //add your varaible names
    var value2 = g_form.getValue('check_box_2'); //add your varaible names
    var value3 = g_form.getValue('check_box_3'); //add your varaible names
   
    if (value1 == 'false' && value2 == 'false' && value3 == 'false') {
        g_form.addErrorMessage("Please select at least 1 variabel");
        return false;
    }
    return true;
}
 
Output-
PrashantAhire_0-1701940898440.png

 

Please check and Mark Correct and Helpful if it really helps you.
Regards,
Prashant Ahire

 

View solution in original post

3 REPLIES 3

Prashant Ahire
Kilo Sage

Hello @SNDP 

You use this onSubmit Client script on variable set - 

I have Trial and Tested in my Instance

 

function onSubmit() {
    var value1 = g_form.getValue('check_box_1'); //add your varaible names
    var value2 = g_form.getValue('check_box_2'); //add your varaible names
    var value3 = g_form.getValue('check_box_3'); //add your varaible names
   
    if (value1 == 'false' && value2 == 'false' && value3 == 'false') {
        g_form.addErrorMessage("Please select at least 1 variabel");
        return false;
    }
    return true;
}
 
Output-
PrashantAhire_0-1701940898440.png

 

Please check and Mark Correct and Helpful if it really helps you.
Regards,
Prashant Ahire

 

Shamma Negi
Kilo Sage
Kilo Sage

This is common use case.

 

Try doing the ui policy action and add label and all checkboxes as mandatory true. Then if you checkbox anyone checkbox it will allow you to submit.

 

Please note create te catalog ui policy on variable set rather on catalog item. Go to your variable set then scroll down you will find ui policy related action create from there.

 

Regards,

Shamma

Regards,Shamma Negi

Akshata T
Tera Guru

@SNDP You can apply UI policy on variable set's variables(under related list of variable). Also you can make mandatory from variables of variable set.