From 737d8995612b2321c6eb728e9ec816fadd1d6487 Mon Sep 17 00:00:00 2001 From: prudvi-sai-posetty Date: Tue, 28 Oct 2025 12:21:33 +0530 Subject: [PATCH 1/3] Create fieldValidation.js --- .../Field Validations/fieldValidation.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Client-Side Components/Client Scripts/Field Validations/fieldValidation.js diff --git a/Client-Side Components/Client Scripts/Field Validations/fieldValidation.js b/Client-Side Components/Client Scripts/Field Validations/fieldValidation.js new file mode 100644 index 0000000000..bf6f297795 --- /dev/null +++ b/Client-Side Components/Client Scripts/Field Validations/fieldValidation.js @@ -0,0 +1,23 @@ +function onLoad(){ + var targetViewName = 'your_target_view_name'; + var requiredFields = ['field1', 'field2', 'field3']; + + var currentViewName = g_form.getViewName(); + + if (currentViewName === targetViewName) { + var emptyFields = []; + + for (var i = 0; i < requiredFields.length; i++) { + var fieldValue = g_form.getValue(requiredFields[i]); + if (!fieldValue || fieldValue.trim() === '') { + emptyFields.push(g_form.getLabelOf(requiredFields[i])); + } + } + + if (emptyFields.length > 0) { + var errorMessage = "The following required fields cannot be empty: " + + emptyFields.join(', '); + g_form.addErrorMessage(errorMessage); + } + } +} From 889bad65e45d05e08fb82eea0262200943df8c63 Mon Sep 17 00:00:00 2001 From: prudvi-sai-posetty Date: Tue, 28 Oct 2025 12:23:50 +0530 Subject: [PATCH 2/3] Create README.md --- .../Client Scripts/Field Validations/README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 Client-Side Components/Client Scripts/Field Validations/README.md diff --git a/Client-Side Components/Client Scripts/Field Validations/README.md b/Client-Side Components/Client Scripts/Field Validations/README.md new file mode 100644 index 0000000000..a2ad327e3d --- /dev/null +++ b/Client-Side Components/Client Scripts/Field Validations/README.md @@ -0,0 +1 @@ +An `onLoad` client script that validates required fields in specific ServiceNow form views. From 7cc76b21234d20cc9383d9a0c615308030c6e9b8 Mon Sep 17 00:00:00 2001 From: prudvi-sai-posetty Date: Tue, 28 Oct 2025 14:34:43 +0530 Subject: [PATCH 3/3] README.md --- .../Client Scripts/Field Validations/README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Client-Side Components/Client Scripts/Field Validations/README.md b/Client-Side Components/Client Scripts/Field Validations/README.md index a2ad327e3d..08cd26b5c3 100644 --- a/Client-Side Components/Client Scripts/Field Validations/README.md +++ b/Client-Side Components/Client Scripts/Field Validations/README.md @@ -1 +1,12 @@ An `onLoad` client script that validates required fields in specific ServiceNow form views. + +This ServiceNow client script provides automatic validation of required form fields when users access specific form views. The script runs immediately when a form loads and checks that critical fields are populated, displaying user-friendly error messages for any missing required information. This ensures data completeness and improves form submission success rates by catching validation issues early in the user workflow. + +What This Script Does: +The onLoad client script performs comprehensive field validation with these key capabilities: +View-Specific Validation: Only triggers validation when accessing a designated form view +Multiple Field Support: Validates multiple required fields simultaneously in a single operation +Smart Field Detection: Uses field labels (not technical names) in error messages for better user experience +Consolidated Error Display: Shows all missing required fields in a single, clear error message +Immediate Feedback: Provides instant validation results as soon as the form loads +Non-Intrusive Design: Displays informational errors without blocking form interaction