diff --git a/Client-Side Components/Client Scripts/Validate Short Description/Readme.md b/Client-Side Components/Client Scripts/Validate Short Description/Readme.md new file mode 100644 index 0000000000..b26cfcfd3e --- /dev/null +++ b/Client-Side Components/Client Scripts/Validate Short Description/Readme.md @@ -0,0 +1,34 @@ +Client Script – Validate Short Description +Overview + +This client script validates the Short Description field before a record is submitted. It ensures that the field: + +Does not exceed 100 characters. + +Does not contain any special characters (only letters, numbers, and spaces are allowed). + +This helps maintain data quality, consistency, and readability in incident records or any other relevant table. + +How It Works + +On form submission, the script checks the short_description field. + +If the description is too long or contains invalid characters, the submission is blocked. + +An error message is displayed, and the problematic field can be optionally highlighted. + +Configuration + +Navigate to System Definition → Client Scripts. + +Create a new client script. + +Set the following properties: + +Table: Incident (or the target table) + +Type: onSubmit + +Active: Checked + +Paste the following script into the Script field. diff --git a/Client-Side Components/Client Scripts/Validate Short Description/Validate Short Description.js b/Client-Side Components/Client Scripts/Validate Short Description/Validate Short Description.js new file mode 100644 index 0000000000..0eda36267d --- /dev/null +++ b/Client-Side Components/Client Scripts/Validate Short Description/Validate Short Description.js @@ -0,0 +1,20 @@ +function onSubmit() { + var shortDescription = g_form.getValue('short_description'); + + // Check for length + if (shortDescription.length > 100) { + alert('Short Description must not be more than 100 characters long.'); + return false; // Prevent form submission + } + + // Check for special characters + var specialCharsRegex = /[^a-zA-Z0-9\s]/g; + var specialChars = shortDescription.match(specialCharsRegex); + + if (specialChars) { + alert('Short Description contains invalid characters: ' + specialChars.join(', ')); + return false; // Prevent form submission + } + + return true; // Allow submission if both checks pass +}