Skip to content

Commit 9385271

Browse files
authored
Merge branch 'main' into feature/Identify-inactive-assignment-groups
2 parents fe08974 + 7f50ab1 commit 9385271

File tree

20 files changed

+371
-1
lines changed

20 files changed

+371
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This project adds a dynamic preview feature to Service Catalog items, allowing users to see the full approval chain before submitting a request. It improves transparency, reduces confusion, and helps users understand who will be involved in the approval process based on their selections.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function onLoad() {
2+
var ga = new GlideAjax('ApprovalChainHelper');
3+
ga.addParam('sysparm_name', 'getApprovers');
4+
ga.addParam('sysparm_item_id', g_form.getUniqueValue());
5+
ga.getXMLAnswer(function(response) {
6+
var approvers = JSON.parse(response);
7+
var message = 'This request will be approved by: ' + approvers.join(', ');
8+
g_form.showFieldMsg('requested_for', message, 'info');
9+
});
10+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var ApprovalChainHelper = Class.create();
2+
ApprovalChainHelper.prototype = Object.extendsObject(AbstractAjaxProcessor, {
3+
getApprovers: function() {
4+
var itemId = this.getParameter('sysparm_item_id');
5+
var userId = gs.getUserID();
6+
7+
var approvers = [];
8+
9+
// Example logic: fetch approval rules based on item and user
10+
var ruleGR = new GlideRecord('sysapproval_approver');
11+
ruleGR.addQuery('document_id', 80f8920bc3e4b2105219daec050131e3);
12+
ruleGR.query();
13+
14+
while (ruleGR.next()) {
15+
approvers.push(ruleGR.approver.name.toString());
16+
}
17+
18+
return JSON.stringify(approvers);
19+
}
20+
});
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+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This project allows users to schedule a Service Catalog request for a future date and time. Instead of submitting immediately, the request is stored and automatically submitted later using a Scheduled Job
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function onSubmit() {
2+
var scheduledTime = g_form.getValue('scheduled_time');
3+
var currentTime = new Date().toISOString();
4+
5+
if (scheduledTime > currentTime) {
6+
var ga = new GlideAjax('ScheduledRequestHelper');
7+
ga.addParam('sysparm_name', 'storeScheduledRequest');
8+
ga.addParam('sysparm_item', g_form.getUniqueValue());
9+
ga.addParam('sysparm_time', scheduledTime);
10+
ga.getXMLAnswer(function(response) {
11+
alert('Your request has been scheduled for: ' + scheduledTime);
12+
});
13+
return false; // Prevent immediate submission
14+
}
15+
16+
return true; // Submit immediately if time is now or past
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var ScheduledRequestHelper = Class.create();
2+
ScheduledRequestHelper.prototype = Object.extendsObject(AbstractAjaxProcessor, {
3+
storeScheduledRequest: function() {
4+
var itemID = this.getParameter('sysparm_item');
5+
var scheduledTime = this.getParameter('sysparm_time');
6+
7+
var record = new GlideRecord('x_snc_scheduled_requests'); // Custom table
8+
record.initialize();
9+
record.catalog_item = itemID;
10+
record.scheduled_time = scheduledTime;
11+
record.insert();
12+
13+
return 'Scheduled successfully';
14+
}
15+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var now = new GlideDateTime();
2+
var gr = new GlideRecord('x_snc_scheduled_requests');
3+
gr.addQuery('scheduled_time', '<=', now);
4+
gr.query();
5+
6+
while (gr.next()) {
7+
var request = new GlideRecord('sc_request');
8+
request.initialize();
9+
request.requested_for = gr.requested_for;
10+
request.cat_item = gr.catalog_item;
11+
request.insert();
12+
13+
gr.deleteRecord(); // Remove after submission
14+
}

0 commit comments

Comments
 (0)