From 6c460d34745eb87bb3c3342792461c27cc75eb0e Mon Sep 17 00:00:00 2001 From: Charanjeet <35090930+Charanjet@users.noreply.github.com> Date: Sat, 18 Oct 2025 13:05:36 +0530 Subject: [PATCH 1/6] Add attachment format validation for incidents --- .../AttachmentFormatValidatorClientScript.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Server-Side Components/Business Rules/AttachmentFormatValidatorClientScript/AttachmentFormatValidatorClientScript.js diff --git a/Server-Side Components/Business Rules/AttachmentFormatValidatorClientScript/AttachmentFormatValidatorClientScript.js b/Server-Side Components/Business Rules/AttachmentFormatValidatorClientScript/AttachmentFormatValidatorClientScript.js new file mode 100644 index 0000000000..79e7a24c51 --- /dev/null +++ b/Server-Side Components/Business Rules/AttachmentFormatValidatorClientScript/AttachmentFormatValidatorClientScript.js @@ -0,0 +1,26 @@ +(function executeRule(current, previous /*null when async*/ ) { + + if (current.table_name == 'incident') { + + // Fetch the file name of the uploaded attachment + var fileName = current.getValue('file_name'); + + // Fetch allowed extensions from system property (comma-separated, lowercase) + var allowedExtensions = gs.getProperty('attachment.format.allowedExtensions', 'pdf,docx,png,jpg') + .toLowerCase() + .split(','); + + var fileExtension = ''; + if (fileName && fileName.indexOf('.') !== -1) { + fileExtension = fileName.split('.').pop().toLowerCase(); + } + + // If file extension not allowed — prevent insert + if (allowedExtensions.indexOf(fileExtension) === -1) { + gs.addErrorMessage('File type "' + fileExtension + '" is not allowed. Allowed types: ' + allowedExtensions.join(', ')); + gs.log('Attachment blocked: Disallowed file type "' + fileExtension + '" for table ' + current.table_name); + current.setAbortAction(true); + return false; + } + } +})(current, previous); From d9086a60b48e35f74adbb6ed12759ae186bb4241 Mon Sep 17 00:00:00 2001 From: Charanjeet <35090930+Charanjet@users.noreply.github.com> Date: Sat, 18 Oct 2025 13:45:57 +0530 Subject: [PATCH 2/6] Add README for Attachment Format Validator Added documentation for the Attachment Format Validator, detailing its functionality, key features, and configuration. --- .../Readme.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Server-Side Components/Business Rules/AttachmentFormatValidatorClientScript/Readme.md diff --git a/Server-Side Components/Business Rules/AttachmentFormatValidatorClientScript/Readme.md b/Server-Side Components/Business Rules/AttachmentFormatValidatorClientScript/Readme.md new file mode 100644 index 0000000000..5a260b2a0d --- /dev/null +++ b/Server-Side Components/Business Rules/AttachmentFormatValidatorClientScript/Readme.md @@ -0,0 +1,17 @@ +The validator runs automatically on the sys_attachment table during record creation and checks each file extension against an allowed list defined in a system property. +If a file type is not allowed, the upload is blocked, the record creation is aborted, and a descriptive error is logged. +**Key Features:** +Server‑side enforcement (cannot be bypassed through APIs or imports). +Configurable allowed file extensions through a single system property. +Optional restriction to specific business tables. +Lightweight validation for secure instance operation. +**Functionality Summary** +Each attachment upload triggers the Business Rule before insert. +The file name and extension are extracted. +Allowed file extensions are read from the system property attachment.format.allowedExtensions. +The script checks whether the uploaded file complies with this configuration. +If disallowed, the upload is rejected and a clear error message appears in the system log or UI. + +**Configuration** +System Property +attachment.format.allowedExtensions - Defines which file types users are allowed to upload - sample values : pdf,docx,xlsx,png,jpg From d470fa23f7159f6b45ab30f46ad5dca6e98800c4 Mon Sep 17 00:00:00 2001 From: Charanjeet <35090930+Charanjet@users.noreply.github.com> Date: Sat, 18 Oct 2025 13:46:37 +0530 Subject: [PATCH 3/6] Rename AttachmentFormatValidatorClientScript.js to AttachmentFormatValidator.js --- ...ormatValidatorClientScript.js => AttachmentFormatValidator.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Server-Side Components/Business Rules/AttachmentFormatValidatorClientScript/{AttachmentFormatValidatorClientScript.js => AttachmentFormatValidator.js} (100%) diff --git a/Server-Side Components/Business Rules/AttachmentFormatValidatorClientScript/AttachmentFormatValidatorClientScript.js b/Server-Side Components/Business Rules/AttachmentFormatValidatorClientScript/AttachmentFormatValidator.js similarity index 100% rename from Server-Side Components/Business Rules/AttachmentFormatValidatorClientScript/AttachmentFormatValidatorClientScript.js rename to Server-Side Components/Business Rules/AttachmentFormatValidatorClientScript/AttachmentFormatValidator.js From f8de44942d14dd8ac3ee6e9500f6d59ea306bf7e Mon Sep 17 00:00:00 2001 From: Charanjeet <35090930+Charanjet@users.noreply.github.com> Date: Sat, 18 Oct 2025 13:49:38 +0530 Subject: [PATCH 4/6] updating the directory --- ...chmentFormatValidatorClientScriptAttachmentFormatValidator.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Server-Side Components/Business Rules/{AttachmentFormatValidatorClientScript/AttachmentFormatValidator.js => AttachmentFormatValidator/AttachmentFormatValidatorClientScriptAttachmentFormatValidator.js} (100%) diff --git a/Server-Side Components/Business Rules/AttachmentFormatValidatorClientScript/AttachmentFormatValidator.js b/Server-Side Components/Business Rules/AttachmentFormatValidator/AttachmentFormatValidatorClientScriptAttachmentFormatValidator.js similarity index 100% rename from Server-Side Components/Business Rules/AttachmentFormatValidatorClientScript/AttachmentFormatValidator.js rename to Server-Side Components/Business Rules/AttachmentFormatValidator/AttachmentFormatValidatorClientScriptAttachmentFormatValidator.js From 10f102e0e8699e73ed5fa49285fe222e1d213fad Mon Sep 17 00:00:00 2001 From: Charanjeet <35090930+Charanjet@users.noreply.github.com> Date: Sat, 18 Oct 2025 13:50:14 +0530 Subject: [PATCH 5/6] Fixing the naming convention --- ...tAttachmentFormatValidator.js => AttachmentFormatValidator.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Server-Side Components/Business Rules/AttachmentFormatValidator/{AttachmentFormatValidatorClientScriptAttachmentFormatValidator.js => AttachmentFormatValidator.js} (100%) diff --git a/Server-Side Components/Business Rules/AttachmentFormatValidator/AttachmentFormatValidatorClientScriptAttachmentFormatValidator.js b/Server-Side Components/Business Rules/AttachmentFormatValidator/AttachmentFormatValidator.js similarity index 100% rename from Server-Side Components/Business Rules/AttachmentFormatValidator/AttachmentFormatValidatorClientScriptAttachmentFormatValidator.js rename to Server-Side Components/Business Rules/AttachmentFormatValidator/AttachmentFormatValidator.js From 13edd29223a6d147b86499adbde32776b561c2b7 Mon Sep 17 00:00:00 2001 From: Charanjeet <35090930+Charanjet@users.noreply.github.com> Date: Sat, 18 Oct 2025 13:51:16 +0530 Subject: [PATCH 6/6] Moving file to another folder --- .../Readme.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Server-Side Components/Business Rules/{AttachmentFormatValidatorClientScript => AttachmentFormatValidator}/Readme.md (100%) diff --git a/Server-Side Components/Business Rules/AttachmentFormatValidatorClientScript/Readme.md b/Server-Side Components/Business Rules/AttachmentFormatValidator/Readme.md similarity index 100% rename from Server-Side Components/Business Rules/AttachmentFormatValidatorClientScript/Readme.md rename to Server-Side Components/Business Rules/AttachmentFormatValidator/Readme.md