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.

submit false when we didn't select any checkbox or any other field

Sirri
Tera Guru

Hi All,

 

I have requirement in catalog there are three checkbox and one multiline text .

No one field is not mandatory.  but when we submit at one field check box or mutli line text will be add.

If we didn't add then submit false.

 

I have return client submit code. Please let us know if i want to modify anything.

 

Please find the attached documents for your reference.

1 ACCEPTED SOLUTION

Danish Bhairag2
Tera Sage

Hi @Sirri ,

 

Plz find the updated code:

 

function onSubmit() {

    // Get the values of the checkboxes and multiline text field

    var checkbox1 = g_form.getValue('checkbox_field_1');

    var checkbox2 = g_form.getValue('checkbox_field_2');

    var checkbox3 = g_form.getValue('checkbox_field_3');

    var multilineText = g_form.getValue('multiline_text_field');

 

    // Check if at least one checkbox is selected or multiline text field is populated

    if ((checkbox1 === 'true' || checkbox2 === 'true' || checkbox3 === 'true') || multilineText) {

        // At least one field is populated, allow the form submission

        return true;

    } else {

        // None of the fields are populated, prevent form submission and show an error message

        alert('Please populate at least one checkbox or multiline text field before submitting the form.');

        return

false;

    }

 

Thanks,

Danish

 

}

View solution in original post

6 REPLIES 6

Anand Kumar P
Giga Patron

Hi @Sirri ,

function onSubmit() {

    var checkbox1 = g_form.getValue('displayname');
    var checkbox2 = g_form.getValue('mobilenumber');
    var checkbox3 = g_form.getValue('checkbox');
    var multilineText = g_form.getValue('additionalcomments');

    if (!(checkbox1 || checkbox2 || checkbox3 || multilineText)) {
        alert('Please fill out at least one field (checkbox or multiline text) before submitting.');
        return false;
    }

    return true;
}

Thanks,

Anand

Hi @Anand Kumar P 

 

Thank you, I have changed in your script return false and return true and the alert message.

but When I try to submit with one value that will not tacking as submission. Please let us know If still I want to modify.

Please find the attached document.