From 5753d3c7012c56811dfc503a5a4c563f81c49c36 Mon Sep 17 00:00:00 2001 From: Maheshkh9738 Date: Tue, 28 Oct 2025 20:34:39 +0530 Subject: [PATCH 1/3] Create Readme.JS --- .../Catalog Client Script/Onsubmit validation/Readme.JS | 1 + 1 file changed, 1 insertion(+) create mode 100644 Client-Side Components/Catalog Client Script/Onsubmit validation/Readme.JS diff --git a/Client-Side Components/Catalog Client Script/Onsubmit validation/Readme.JS b/Client-Side Components/Catalog Client Script/Onsubmit validation/Readme.JS new file mode 100644 index 0000000000..6de0662aab --- /dev/null +++ b/Client-Side Components/Catalog Client Script/Onsubmit validation/Readme.JS @@ -0,0 +1 @@ +This project adds pre-validation for hardware availability in ServiceNow Catalog Items. Before submitting a request, the system checks if the requested hardware is available in inventory and blocks submission if stock is insufficient. we can easy to extend other validations (budget, licenses, etc.).Improves user experience by validating before approval.Prevents unnecessary approvals and fulfillment. From 8fa5a6622a58c69e8774c47b195a872246df999a Mon Sep 17 00:00:00 2001 From: Maheshkh9738 Date: Tue, 28 Oct 2025 20:35:36 +0530 Subject: [PATCH 2/3] Create submit validation client script.js --- .../submit validation client script | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Client-Side Components/Catalog Client Script/Onsubmit validation/submit validation client script diff --git a/Client-Side Components/Catalog Client Script/Onsubmit validation/submit validation client script b/Client-Side Components/Catalog Client Script/Onsubmit validation/submit validation client script new file mode 100644 index 0000000000..64a30bb464 --- /dev/null +++ b/Client-Side Components/Catalog Client Script/Onsubmit validation/submit validation client script @@ -0,0 +1,30 @@ +function onSubmit() { + + + var hardware = g_form.getValue('hardware_name'); + var qty = g_form.getValue('quantity'); + + + + var ga = new GlideAjax('HardwareValidationUtils'); + ga.addParam('sysparm_name', 'validateHardware'); + ga.addParam('sysparm_hardware', hardware); + ga.addParam('sysparm_quantity', qty); + + + ga.getXMLAnswer(function(response) { + + + if (response !== 'OK') { + alert(response); + + g_form.addErrorMessage(response); // Optional inline error + g_form.setSubmit(false); // Prevent submission in Service Portal + } else { + + g_form.setSubmit(true); // Allow submission + } + }); + + return false; +} From 6d4a5101fbd2e5bfaa33dce613976bcd31a39994 Mon Sep 17 00:00:00 2001 From: Maheshkh9738 Date: Tue, 28 Oct 2025 20:36:10 +0530 Subject: [PATCH 3/3] Create on submit scriptinclude.JS --- .../on submit scriptinclude.JS | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Client-Side Components/Catalog Client Script/Onsubmit validation/on submit scriptinclude.JS diff --git a/Client-Side Components/Catalog Client Script/Onsubmit validation/on submit scriptinclude.JS b/Client-Side Components/Catalog Client Script/Onsubmit validation/on submit scriptinclude.JS new file mode 100644 index 0000000000..bcb4631341 --- /dev/null +++ b/Client-Side Components/Catalog Client Script/Onsubmit validation/on submit scriptinclude.JS @@ -0,0 +1,25 @@ +var HardwareValidationUtils = Class.create(); +HardwareValidationUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, { + + validateHardware: function() { + var hardware = this.getParameter('sysparm_hardware'); + var qty = parseInt(this.getParameter('sysparm_quantity'), 10); + + if (!hardware || isNaN(qty)) { + return 'Invalid input!'; + } + + var gr = new GlideRecord('u_hardware_inventory'); + if (gr.get(hardware)) { + var availableQty = parseInt(gr.getValue('available_quantity'), 10); + if (availableQty >= qty) { + return 'OK'; + } else { + return 'Not enough stock available!'; + } + } + return 'Hardware not found!'; + }, + + type: 'HardwareValidationUtils' +});