Skip to content

Commit 8225905

Browse files
authored
Attachment Format Validator (Business Rule), a server‑side mechanism (#2246)
* Add attachment format validation for incidents * Add README for Attachment Format Validator Added documentation for the Attachment Format Validator, detailing its functionality, key features, and configuration. * Rename AttachmentFormatValidatorClientScript.js to AttachmentFormatValidator.js * updating the directory * Fixing the naming convention * Moving file to another folder
1 parent 35372f3 commit 8225905

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
(function executeRule(current, previous /*null when async*/ ) {
2+
3+
if (current.table_name == 'incident') {
4+
5+
// Fetch the file name of the uploaded attachment
6+
var fileName = current.getValue('file_name');
7+
8+
// Fetch allowed extensions from system property (comma-separated, lowercase)
9+
var allowedExtensions = gs.getProperty('attachment.format.allowedExtensions', 'pdf,docx,png,jpg')
10+
.toLowerCase()
11+
.split(',');
12+
13+
var fileExtension = '';
14+
if (fileName && fileName.indexOf('.') !== -1) {
15+
fileExtension = fileName.split('.').pop().toLowerCase();
16+
}
17+
18+
// If file extension not allowed — prevent insert
19+
if (allowedExtensions.indexOf(fileExtension) === -1) {
20+
gs.addErrorMessage('File type "' + fileExtension + '" is not allowed. Allowed types: ' + allowedExtensions.join(', '));
21+
gs.log('Attachment blocked: Disallowed file type "' + fileExtension + '" for table ' + current.table_name);
22+
current.setAbortAction(true);
23+
return false;
24+
}
25+
}
26+
})(current, previous);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
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.
2+
If a file type is not allowed, the upload is blocked, the record creation is aborted, and a descriptive error is logged.
3+
**Key Features:**
4+
Server‑side enforcement (cannot be bypassed through APIs or imports).
5+
Configurable allowed file extensions through a single system property.
6+
Optional restriction to specific business tables.
7+
Lightweight validation for secure instance operation.
8+
**Functionality Summary**
9+
Each attachment upload triggers the Business Rule before insert.
10+
The file name and extension are extracted.
11+
Allowed file extensions are read from the system property attachment.format.allowedExtensions.
12+
The script checks whether the uploaded file complies with this configuration.
13+
If disallowed, the upload is rejected and a clear error message appears in the system log or UI.
14+
15+
**Configuration**
16+
System Property
17+
attachment.format.allowedExtensions - Defines which file types users are allowed to upload - sample values : pdf,docx,xlsx,png,jpg

0 commit comments

Comments
 (0)