Make checkboxes variables mandatory on record producer form submission

Renu9
Tera Contributor

Hi All,

I'm having a record producer where I am using  2 checkboxes variables ,for both of them I checked mandatory checkbox.

But when I submit the record producer form, even if 1 checkbox is selected then the record is getting submitted. But generally if both are checked then only the form has to submit.

Please let me know what steps are to be taken?

Renu9_0-1702978018848.png

 

1 ACCEPTED SOLUTION

Amit Verma
Kilo Patron
Kilo Patron

Hi @Renu9 

 

As you are working with Service Catalog, all the checkboxes are automatically clubbed under options label. To achieve your requirement, you can make use of an On-Submit client script. Please find a snip below for your reference :

 

AmitVerma_0-1702980826634.png

 

Please configure this client script on your catalog item and this should work.

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

View solution in original post

4 REPLIES 4

Amit Verma
Kilo Patron
Kilo Patron

Hi @Renu9 

 

I think you have not enabled "Selection Required" field while configuring the checkbox variables, you have only done it for the label . Please check on that.

 

Moreover, you can have an On-Submit client script on the record producer which can check if both the checkboxes are checked or not before the submission is done.

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Renu9
Tera Contributor

Hi @Amit Verma 

For both checkboxes I have selected "Selection Required" as checked. And also I dint create any label. Directly I could see wording 'options' came and as mandatory. I dint set anything to make the options as mandatory as well

Amit Verma
Kilo Patron
Kilo Patron

Hi @Renu9 

 

As you are working with Service Catalog, all the checkboxes are automatically clubbed under options label. To achieve your requirement, you can make use of an On-Submit client script. Please find a snip below for your reference :

 

AmitVerma_0-1702980826634.png

 

Please configure this client script on your catalog item and this should work.

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Namrata Ghorpad
Mega Sage
Mega Sage

Hello @Renu9 ,

Write Catalog Client Script like below.

function onSubmit(){
    //Set the mandatory checkbox variable names and total mandatory count here
    var mandatoryVars = 'md,do,pa,pa_c,pt,pharm_d,aprn_cp,aprn_cnm,rn,lpn,ma,phd,lpc,msw,lcsw,ld,crna,mha';
    var mandatoryCount = 1;
   
    var passed = forceMandatoryCheckboxes(mandatoryVars, mandatoryCount);
    var getType = g_form.getValue('Chcekbox variable name'); //is it a "bug"?

    if(!passed && getType == 'bug'){
        //Abort the submit
        alert('You must select at least ' + mandatoryCount + ' options.');
        return false;
    }
}

function forceMandatoryCheckboxes(mandatory, count){
    //Split the mandatory variable names into an array
    mandatory = mandatory.split(',');
    var answer = false;
    var varFound = false;
    var numTrue = 0;
    //Check each variable in the array
    for(x=0;x<mandatory.length;x++){
        //Check to see if variable exists
        if(g_form.getControl(mandatory[x])){
            varFound = true;
            //Check to see if variable is set to 'true'
            if(g_form.getValue(mandatory[x]) == 'true'){
                numTrue ++;
                //Exit the loop if we have reached required number of 'true'
                if(numTrue >= count){
                    answer = true;
                    break;
                }
            }
        }
    }
    //If we didn't find any of the variables allow the submit
    if(varFound == false){
        answer = true;
    }
    //Return true or false
    return answer;
}

 and refer the below link.

https://www.servicenow.com/community/developer-forum/how-to-make-a-group-of-checkboxes-mandatory/m-p... 

 

Please mark my answer as correct and helpful if it resolves your issue.

 

Regards,

Namrata