We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to display an error message when condition(s) are no me

ID NOBLE
Tera Expert

Please I have a requirement to display an error message "Must provide a reason(s) for your selection".

 

We have a variable of type "SELECT BOX" with options: True, False, Unknown. So, when a user select "False" from these options, the above error message (in red color) must automatically display to users. Please how do I do this?

 

Thanks.

1 ACCEPTED SOLUTION

@ID NOBLE 

 

You can make use of an On-Submit Catalog Client Script. Please refer below screenshots :

AmitVerma_0-1733893530043.png

 

 

function onSubmit() {
    var userChoice = g_form.getValue('user_choice'); // Please replace with your catalog variable
    if (userChoice == 'false') {
        g_form.addErrorMessage('Please provide a reason for your selection before submitting');
        return false;
    }
}

 

 

AmitVerma_1-1733893587402.png

 

Thanks and Regards
Amit Verma

View solution in original post

12 REPLIES 12

vermaamit16
Kilo Patron

Hi @ID NOBLE 

 

As requested by @AshishKM , you need to provide more details so that we can assist you further. Although, you can refer below reference example in which I have made use of a UI Policy to set field message on selection of a particular choice ( in your case, false) in a catalog item.

 

AmitVerma_0-1733808078194.png

 

AmitVerma_1-1733808090694.png

 

AmitVerma_2-1733808123772.png

 

AmitVerma_3-1733808148810.png

 

Thanks and Regards

Amit Verma

Thanks and Regards
Amit Verma

@vermaamit16,

 

Thank you, when I used this method, the error message displayed, but I was still able to submit the form which we don't want. Please what more should I add to make the user(s) unable to submit the form unless they meet the specified condition?

I really appreciate your support.

@ID NOBLE 

 

You can make use of an On-Submit Catalog Client Script. Please refer below screenshots :

AmitVerma_0-1733893530043.png

 

 

function onSubmit() {
    var userChoice = g_form.getValue('user_choice'); // Please replace with your catalog variable
    if (userChoice == 'false') {
        g_form.addErrorMessage('Please provide a reason for your selection before submitting');
        return false;
    }
}

 

 

AmitVerma_1-1733893587402.png

 

Thanks and Regards
Amit Verma