Skip to content

Commit 303a732

Browse files
authored
Enforce File Upload Restrictions for HR Document Submission (#1172)
1 parent 3c53f97 commit 303a732

File tree

2 files changed

+28
-0
lines changed
  • Business Rules/Enforce File Upload Restrictions for HR Document Submission

2 files changed

+28
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var hrTask = new GlideRecord('sn_hr_core_task');
2+
3+
if (hrTask.get(current.table_sys_id) &&
4+
hrTask.hr_Task_type == 'upload_documents' &&
5+
hrTask.short_description == 'submit photo identification') {
6+
7+
var fileName = current.file_name.toString();
8+
var fileSize = current.size_bytes.toString();
9+
var fileType = fileName.split('.').pop().toLowerCase();
10+
11+
// Check file size (must not exceed 2MB)
12+
if (parseInt(fileSize) > 2000000) { // 2MB in bytes
13+
gs.addErrorMessage('Maximum file size is 2 MB');
14+
current.setAbortAction(true); // Abort if file size exceeds 2 MB
15+
return;
16+
}
17+
18+
// Check file type (must be JPG or JPEG)
19+
if (fileType !== 'jpg' && fileType !== 'jpeg') {
20+
gs.addErrorMessage('File must be in JPG or JPEG format');
21+
current.setAbortAction(true); // Abort if not JPG or JPEG
22+
return;
23+
}
24+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This code ensures that when a user uploads a document related to a specific HR task, the uploaded file meets
2+
certain criteria: it must be in JPG or JPEG format and must not exceed 2 MB in size. If either condition is violated,
3+
the upload is halted, and an appropriate error message is displayed to the user, maintaining the integrity of the data
4+
being processed.

0 commit comments

Comments
 (0)