Skip to content

Commit de359a1

Browse files
authored
Catalog Item with Document Upload & Validation (#2619)
* Create Readme.md * Create Client script.JS * Create Script include.js
1 parent 1275adb commit de359a1

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function onSubmit() {
2+
var ga = new GlideAjax('DocumentValidationHelper');
3+
ga.addParam('sysparm_name', 'validateAttachments');
4+
ga.addParam('sysparm_item_id', g_form.getUniqueValue());
5+
ga.getXMLAnswer(function(response) {
6+
if (response !== 'valid') {
7+
alert('Document validation failed: ' + response);
8+
return false;
9+
}
10+
});
11+
return true;
12+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.
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)