Skip to content

Commit a7788aa

Browse files
authored
Merge branch 'main' into 4th-pull-request
2 parents 194ad68 + 24da1e0 commit a7788aa

File tree

7 files changed

+212
-0
lines changed

7 files changed

+212
-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+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Safe Bulk Record Update with Logging
2+
3+
## Overview
4+
Efficiently update multiple records in batch with error handling, progress tracking, and logging to prevent timeouts and data loss.
5+
6+
## What It Does
7+
- Updates records in configurable batch sizes
8+
- Logs progress for monitoring
9+
- Handles individual record errors without stopping batch
10+
- Prevents script timeout with batch processing
11+
- Tracks success/failure counts
12+
- Logs detailed error information
13+
14+
## Use Cases
15+
- Bulk data migrations
16+
- Mass field updates after deployment
17+
- Scheduled bulk corrections
18+
- Data cleanup operations
19+
- Batch status updates across records
20+
21+
## Files
22+
- `bulk_update_with_progress.js` - Background Script for safe bulk updates
23+
24+
## How to Use
25+
26+
### Option 1: Run as Background Script
27+
1. Go to **System Diagnostics > Script Background**
28+
2. Copy code from `bulk_update_with_progress.js`
29+
3. Modify the table name and query filter
30+
4. Execute and monitor logs
31+
32+
### Option 2: Create as Scheduled Job
33+
1. Go to **System Scheduler > Scheduled Jobs**
34+
2. Create new job with the script code
35+
3. Schedule for off-peak hours
36+
4. Logs will be available in System Logs
37+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
var TABLE = 'incident'; // Change to your table
2+
var FILTER = "priority=1"; // Add your filter conditions
3+
var FIELD_TO_UPDATE = 'state'; // Field to update
4+
var NEW_VALUE = '1'; // Value to set
5+
6+
var successCount = 0;
7+
//using gs.info for best logging
8+
gs.info('[Bulk Update Started] Table: ' + TABLE + ' | Filter: ' + FILTER, 'BulkUpdate');
9+
10+
try {
11+
var gr = new GlideRecord(TABLE);
12+
gr.addEncodedQuery(FILTER);
13+
gr.query();
14+
15+
// Collect all record IDs first (single query)
16+
var recordIds = [];
17+
while (gr.next()) {
18+
recordIds.push(gr.getUniqueValue());
19+
}
20+
21+
//using updateMultiple will update all records at once
22+
if (recordIds.length > 0) {
23+
var updateGr = new GlideRecord(TABLE);
24+
updateGr.addEncodedQuery(FILTER);
25+
updateGr.setValue(FIELD_TO_UPDATE, NEW_VALUE);
26+
updateGr.updateMultiple();//this is more efficient
27+
successCount = recordIds.length;
28+
gs.info('[Bulk Update Complete] Total Updated: ' + successCount, 'BulkUpdate');
29+
} else {
30+
gs.info('[Bulk Update] No records matched the filter criteria', 'BulkUpdate');
31+
}
32+
} catch (e) {
33+
gs.error('[Bulk Update Error] ' + e.toString(), 'BulkUpdate');
34+
}

0 commit comments

Comments
 (0)