Skip to content

Commit ba22acd

Browse files
authored
Merge branch 'ServiceNowDevProgram:main' into main
2 parents 6065b0b + d9e42aa commit ba22acd

File tree

89 files changed

+3392
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+3392
-1
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* The following is a client callable script include. This can be used with the onChange Client script to be able to gather the data on the server side
3+
*/
4+
5+
var ReferenceQualifierAjaxHelper = Class.create();
6+
ReferenceQualifierAjaxHelper.prototype = Object.extendsObject(AbstractAjaxProcessor, {
7+
getUserInformation : function() {
8+
var userID = this.getParameter('sysparm_user');
9+
var userRec = new GlideRecord('sys_user');
10+
11+
if(userRec.get(userID)) {
12+
var results = {
13+
"email" : userRec.getValue('email'),
14+
"department" : userRec.getValue('department'),
15+
"title" : userRec.getValue('title'),
16+
"phone" : userRec.getValue('phone')
17+
};
18+
19+
return JSON.stringify(results)
20+
}
21+
22+
},
23+
24+
type: 'ReferenceQualifierAjaxHelper'
25+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Overview
2+
This onchange catalog client script and script inlcude work together autopopulate the user fields that might show up on a catalog item. In the
3+
global scope you will have to create the client callable script include to be able to use the Ajax call that is in the on change client script.
4+
In this example we use the OOB Requested For field that already auto populates the user that is logged in then we go to the server to get that
5+
users information. The fields that are brough back are the ones that are in the code but you can modify to bring back more or less fields if needed.
6+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* In order for this to work make sure to have an onChange catalog client script on a variable that is type Requested For. This variable
3+
* already autopopulates the logged in user with its OOB functionality. In the updateUserFields function you can add any other user fields
4+
* that you might need.
5+
*/
6+
7+
function onChange(control, oldValue, newValue, isLoading) {
8+
//This variable will store the sys_id of the user that populates in your requested for variable
9+
var userID = newValue;
10+
11+
var ga = new GlideAjax(ReferenceQualifierAjaxHelper);
12+
ga.addParam('sysparm_name', 'getUserInformation');
13+
ga.addParam('sysparm_user', userID);
14+
ga.getXMLAnswer(updateUserFields);
15+
16+
function updateUserFields(response) {
17+
var returnedData = JSON.parse(response);
18+
g_form.setValue("email", returnedData.email);
19+
g_form.setValue("department", returnedData.department);
20+
g_form.setValue("title", returnedData.title);
21+
g_form.setValue("phone", returnedData.phone);
22+
}
23+
}
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 introduces a collaboration feature for Service Catalog requests, allowing multiple users to contribute to a single request. It’s ideal for scenarios like team onboarding, shared resource provisioning, or cross-functional workflows.

0 commit comments

Comments
 (0)