Skip to content

Commit edaf93b

Browse files
authored
Merge branch 'main' into sixth-pull-request
2 parents f8dffda + 24da1e0 commit edaf93b

File tree

5 files changed

+141
-0
lines changed

5 files changed

+141
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Show previous request ON requested for selection
2+
3+
This feature enhances the Service Catalog experience by displaying previous requests for the selected Requested For user. When a user selects the Requested For variable in a catalog item form, a confirmation message appears showing the last few requests created for that user.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function onChange(control, oldValue, newValue, isLoading) {
2+
if (isLoading || newValue == '') return;
3+
4+
var ga = new GlideAjax('PreviousRequestsUtils');
5+
ga.addParam('sysparm_name', 'getPreviousRequests');
6+
ga.addParam('sysparm_requested_for', newValue);
7+
ga.getXMLAnswer(function(response) {
8+
var requests = JSON.parse(response);
9+
if (requests.length === 0) {
10+
alert('No previous requests found for this user.');
11+
} else {
12+
var message = 'Previous Requests:\n\n';
13+
requests.forEach(function(req) {
14+
message += 'Number: ' + req.number + ' | Item: ' + req.item + ' | Date: ' + req.date + '\n';
15+
});
16+
if (confirm(message + '\nDo you want to continue?')) {
17+
// User clicked OK
18+
} else {
19+
// User clicked Cancel
20+
g_form.setValue('requested_for', oldValue);
21+
}
22+
}
23+
});
24+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var PreviousRequestsUtils = Class.create();
2+
PreviousRequestsUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
3+
getPreviousRequests: function() {
4+
var requestedFor = this.getParameter('sysparm_requested_for');
5+
var result = [];
6+
var gr = new GlideRecord('sc_req_item');
7+
gr.addQuery('requested_for', requestedFor);
8+
gr.orderByDesc('sys_created_on');
9+
gr.setLimit(5); // Show last 5 requests
10+
gr.query();
11+
while (gr.next()) {
12+
result.push({
13+
number: gr.number.toString(),
14+
item: gr.cat_item.getDisplayValue(),
15+
date: gr.sys_created_on.getDisplayValue()
16+
});
17+
}
18+
return JSON.stringify(result);
19+
}
20+
});
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
README — Client Script: Validate Interaction Resolution
2+
📌 Purpose
3+
This Client Script ensures proper validation when resolving an Interaction record in ServiceNow.
4+
It prevents a user from marking an Interaction as Closed Complete without proper justification.
5+
6+
🎯 What It Does
7+
8+
When a user attempts to submit the form:
9+
✔ Allows submission only if:
10+
Interaction Type is "walkup"
11+
And Related Task Boolean is true
12+
13+
OR
14+
15+
✔ If work notes are provided for First Contact Resolution (FCR)
16+
❌ Prevents submission if:
17+
State = Closed Complete
18+
Work Notes are empty
19+
And no related task condition is met
20+
21+
🧠 Validations Performed
22+
Field Condition Action
23+
state closed_complete Trigger validation
24+
type walkup AND u_boolean_no_related_task = true Submission allowed ✅
25+
work_notes Must not be empty Show error & stop submission ❌
26+
🔔 User Feedback
27+
28+
If work notes are missing:
29+
Displays inline field message
30+
31+
Shows popup alert:
32+
"Provide Worknotes for FCR Interaction"
33+
34+
📍 Script Location
35+
36+
Client Script → Type: onSubmit()
37+
Applicable to Interaction table (interaction)
38+
39+
📌 Script Code
40+
//Client Script to validate an Interaction record is resolved with out any related record created.
41+
function onSubmit() {
42+
var relatedTask = g_form.getValue('u_boolean_no_related_task');
43+
var state = g_form.getValue('state');
44+
var type = g_form.getValue('type');
45+
var workNotes = g_form.getValue('work_notes'); // Get the value of work notes
46+
47+
// Clear previous field messages
48+
g_form.clearMessages();
49+
50+
// Check if state is changing to 'Closed Complete'
51+
if (state == 'closed_complete') {
52+
// Check additional conditions
53+
if (type == 'walkup' && relatedTask == 'true') {
54+
return true; // Allow form submission
55+
} else if (!workNotes) { // Check if work notes is empty
56+
g_form.showFieldMsg('work_notes', 'Provide Worknotes for FCR Interaction', 'error');
57+
alert('Provide Worknotes for FCR Interaction');
58+
return false; // Prevent form submission
59+
}
60+
}
61+
return true; // Allow form submission for other states
62+
}
63+
64+
✅ Benefits
65+
66+
Maintains consistent resolution standards
67+
Ensures justification/documentation for FCR interactions
68+
Reduces incorrect closure of requests without related actions
69+
70+
71+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//Client Script to validate an Interaction record is resolved with out any related record created.
2+
function onSubmit() {
3+
var relatedTask = g_form.getValue('u_boolean_no_related_task');
4+
var state = g_form.getValue('state');
5+
var type = g_form.getValue('type');
6+
var workNotes = g_form.getValue('work_notes'); // Get the value of work notes
7+
8+
// Clear previous field messages
9+
g_form.clearMessages();
10+
11+
// Check if state is changing to 'Closed Complete'
12+
if (state == 'closed_complete') {
13+
// Check additional conditions
14+
if (type == 'walkup' && relatedTask == 'true') {
15+
return true; // Allow form submission
16+
} else if (!workNotes) { // Check if work notes is empty
17+
g_form.showFieldMsg('work_notes', 'Provide Worknotes for FCR Interaction', 'error');
18+
alert('Provide Worknotes for FCR Interaction');
19+
return false; // Prevent form submission
20+
}
21+
}
22+
return true; // Allow form submission for other states
23+
}

0 commit comments

Comments
 (0)