Skip to content

Commit eae69d7

Browse files
Merge branch 'ServiceNowDevProgram:main' into First-Contribution
2 parents 5bf508c + 7078253 commit eae69d7

File tree

15 files changed

+321
-1
lines changed

15 files changed

+321
-1
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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Show Open Incident of caller
2+
3+
Script Type: UI Macro
4+
5+
Goal: In Form view caller can see what are the open incident of that particular caller.
6+
7+
Walk through of code: So for this use case a new macro will be added to the caller field, when it is triggered it will open a new popup window where it will show the list of particular caller which are all open incident.So for this a new UImacro have been used in that a new list icon have been rendered from the db_image table and inside that a showopentckts() function this will get the current caller and then add the query to filter out the list of open incident and then open a popup to show the list of that particular caller which are all open(other than Closed and Cancelled).
8+
9+
Note: To inherite the UI Macro in that particular field (Caller) we need to add the attribute in the Dictionary Entry = ref_contributions=caller_inc_lists [ref_contributions="name of the macro"]
10+
11+
UI Macro
12+
<img width="853" height="292" alt="UIMacro" src="https://github.com/user-attachments/assets/f5b353a2-ffb6-4e44-a740-9905b33cb484" />
13+
14+
Dictonary Entry in Attribute section
15+
<img width="848" height="386" alt="UIMacroDictionary" src="https://github.com/user-attachments/assets/b21d2077-3df5-4408-9bb3-c0672fd1398b" />
16+
17+
UI Macro in Incident Form near the Caller Field
18+
<img width="860" height="310" alt="From UIMacro" src="https://github.com/user-attachments/assets/c3867abf-f9cd-4947-a7e9-41c83189681d" />
19+
20+
Result:
21+
<img width="865" height="409" alt="UIMacro Result" src="https://github.com/user-attachments/assets/5412b29b-e96b-4455-a3e0-5552c9680600" />
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
3+
4+
<img src='sn_tile_icon/now-checklist.svg' stype='width=5%,height:5%' onclick="showopentckts()" title="Show Open Incident of me"></img>
5+
6+
<script language="javascript">
7+
function showopentckts(){
8+
var name=g_form.getValue("caller_id");
9+
var tableName='incident';
10+
var url=tableName+'_list.do?sysparm_query=caller_id='+name+'^stateNOT IN7,8';
11+
window.open(url,'OpenIncident',"popup");
12+
}
13+
14+
</script>
15+
16+
</j:jelly>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# ServiceNow Background Script – Identify Inactive Users with Open Incidents
2+
3+
This background script helps admin to identify **inactive users** who still have **open incidents** assigned to them.
4+
It’s particularly useful during **user cleanup, offboarding audits, or reassignment activities** to ensure no tickets remain unaddressed.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var user = new GlideRecord('sys_user');
2+
user.addQuery('active', false);
3+
user.query();
4+
while (user.next()) {
5+
var inc = new GlideRecord('incident');
6+
inc.addQuery('assigned_to', user.sys_id);
7+
inc.addQuery('state', '!=', 7); // not Closed
8+
inc.query();
9+
while (inc.next()) {
10+
gs.info('Inactive user with open ticket: ' + user.name + ' → ' + inc.number);
11+
}
12+
}
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+

0 commit comments

Comments
 (0)