diff --git a/Client-Side Components/Catalog Client Script/Document validation/Client script.JS b/Client-Side Components/Catalog Client Script/Document validation/Client script.JS new file mode 100644 index 0000000000..c6e4447e7d --- /dev/null +++ b/Client-Side Components/Catalog Client Script/Document validation/Client script.JS @@ -0,0 +1,12 @@ +function onSubmit() { + var ga = new GlideAjax('DocumentValidationHelper'); + ga.addParam('sysparm_name', 'validateAttachments'); + ga.addParam('sysparm_item_id', g_form.getUniqueValue()); + ga.getXMLAnswer(function(response) { + if (response !== 'valid') { + alert('Document validation failed: ' + response); + return false; + } + }); + return true; +} diff --git a/Client-Side Components/Catalog Client Script/Document validation/Readme.md b/Client-Side Components/Catalog Client Script/Document validation/Readme.md new file mode 100644 index 0000000000..66975c579e --- /dev/null +++ b/Client-Side Components/Catalog Client Script/Document validation/Readme.md @@ -0,0 +1 @@ +This project enhances a Service Catalog item by allowing users to upload supporting documents (e.g., ID proof, approval letters) and validating them before the request is submitted. It ensures compliance, completeness, and proper documentation for sensitive or regulated requests. diff --git a/Client-Side Components/Catalog Client Script/Document validation/Script include.js b/Client-Side Components/Catalog Client Script/Document validation/Script include.js new file mode 100644 index 0000000000..71c25a3771 --- /dev/null +++ b/Client-Side Components/Catalog Client Script/Document validation/Script include.js @@ -0,0 +1,22 @@ +var DocumentValidationHelper = Class.create(); +DocumentValidationHelper.prototype = Object.extendsObject(AbstractAjaxProcessor, { + validateAttachments: function() { + var itemId = this.getParameter('sysparm_item_id'); + var attachmentGR = new GlideRecord('sys_attachment'); + attachmentGR.addQuery('table_name', 'sc_req_item'); + attachmentGR.addQuery('table_sys_id', itemId); + attachmentGR.query(); + + while (attachmentGR.next()) { + var fileName = attachmentGR.file_name.toLowerCase(); + if (!fileName.endsWith('.pdf') && !fileName.endsWith('.docx')) { + return 'Only PDF or DOCX files are allowed.'; + } + if (attachmentGR.size_bytes > 5 * 1024 * 1024) { + return 'File size exceeds 5MB limit.'; + } + } + + return 'valid'; + } +});