- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2024 02:26 PM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2024 09:08 PM
You can make use of an On-Submit Catalog Client Script. Please refer below screenshots :
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;
}
}
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2024 02:42 PM - edited 12-09-2024 02:42 PM
Hi @ID NOBLE ,
If this is for any catalog item, then write catalog client script [onChange] on select box varilables.
In the script code check the select box variable value and display the message ( Info or Error ). Error message shows in red.
To create an onChange client script for a ServiceNow catalog item with a select box that displays an error message based on the selected value, follow these steps:
- Navigate to your catalog item in ServiceNow.
- Scroll down to the "Catalog Client Scripts" related list and click "New".
- Set the "Type" to "onChange".
- In the "Field name" field, enter the name of your select box variable.
- In the "Script" field, enter the following code:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue == 'False') {
g_form.addErrorMessage('Must provide a reason(s) for your selection.');
} else {
g_form.clearMessages();
}
}
-Thanks,
AshishKM
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2024 03:22 PM
Thanks for your response. I have just followed the above steps, but it does not work. Can you please help check again?
Once again, thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2024 06:39 PM - edited 12-09-2024 06:41 PM
Please share more detail like, where you are using this script.
What's the select box variable name and its choice value.
Add some screen shorts.
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2024 07:17 AM
Thank you. It's for a variable set and the variable name is "Has the form been filled and signed? (True/False).
Expected error message if FALSE is selected: Must provide a reason(s) for your selection