Skip to content

Commit 3a3843d

Browse files
authored
Create Script include.js
1 parent b506db1 commit 3a3843d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var DocumentValidationHelper = Class.create();
2+
DocumentValidationHelper.prototype = Object.extendsObject(AbstractAjaxProcessor, {
3+
validateAttachments: function() {
4+
var itemId = this.getParameter('sysparm_item_id');
5+
var attachmentGR = new GlideRecord('sys_attachment');
6+
attachmentGR.addQuery('table_name', 'sc_req_item');
7+
attachmentGR.addQuery('table_sys_id', itemId);
8+
attachmentGR.query();
9+
10+
while (attachmentGR.next()) {
11+
var fileName = attachmentGR.file_name.toLowerCase();
12+
if (!fileName.endsWith('.pdf') && !fileName.endsWith('.docx')) {
13+
return 'Only PDF or DOCX files are allowed.';
14+
}
15+
if (attachmentGR.size_bytes > 5 * 1024 * 1024) {
16+
return 'File size exceeds 5MB limit.';
17+
}
18+
}
19+
20+
return 'valid';
21+
}
22+
});

0 commit comments

Comments
 (0)