Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
README — Client Script: Validate Interaction Resolution
📌 Purpose
This Client Script ensures proper validation when resolving an Interaction record in ServiceNow.
It prevents a user from marking an Interaction as Closed Complete without proper justification.

🎯 What It Does

When a user attempts to submit the form:
✔ Allows submission only if:
Interaction Type is "walkup"
And Related Task Boolean is true

OR
✔ If work notes are provided for First Contact Resolution (FCR)
❌ Prevents submission if:
State = Closed Complete
Work Notes are empty
And no related task condition is met

🧠 Validations Performed
Field Condition Action
state closed_complete Trigger validation
type walkup AND u_boolean_no_related_task = true Submission allowed ✅
work_notes Must not be empty Show error & stop submission ❌
🔔 User Feedback

If work notes are missing:
Displays inline field message

Shows popup alert:
"Provide Worknotes for FCR Interaction"

📍 Script Location

Client Script → Type: onSubmit()
Applicable to Interaction table (interaction)

📌 Script Code
//Client Script to validate an Interaction record is resolved with out any related record created.
function onSubmit() {
var relatedTask = g_form.getValue('u_boolean_no_related_task');
var state = g_form.getValue('state');
var type = g_form.getValue('type');
var workNotes = g_form.getValue('work_notes'); // Get the value of work notes

// Clear previous field messages
g_form.clearMessages();

// Check if state is changing to 'Closed Complete'
if (state == 'closed_complete') {
// Check additional conditions
if (type == 'walkup' && relatedTask == 'true') {
return true; // Allow form submission
} else if (!workNotes) { // Check if work notes is empty
g_form.showFieldMsg('work_notes', 'Provide Worknotes for FCR Interaction', 'error');
alert('Provide Worknotes for FCR Interaction');
return false; // Prevent form submission
}
}
return true; // Allow form submission for other states
}

✅ Benefits

Maintains consistent resolution standards
Ensures justification/documentation for FCR interactions
Reduces incorrect closure of requests without related actions
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//Client Script to validate an Interaction record is resolved with out any related record created.
function onSubmit() {
var relatedTask = g_form.getValue('u_boolean_no_related_task');
var state = g_form.getValue('state');
var type = g_form.getValue('type');
var workNotes = g_form.getValue('work_notes'); // Get the value of work notes

// Clear previous field messages
g_form.clearMessages();

// Check if state is changing to 'Closed Complete'
if (state == 'closed_complete') {
// Check additional conditions
if (type == 'walkup' && relatedTask == 'true') {
return true; // Allow form submission
} else if (!workNotes) { // Check if work notes is empty
g_form.showFieldMsg('work_notes', 'Provide Worknotes for FCR Interaction', 'error');
alert('Provide Worknotes for FCR Interaction');
return false; // Prevent form submission
}
}
return true; // Allow form submission for other states
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
📘 README — Auto Assignment by Application Group Variable
ServiceNow Business Rule — sc_req_item
✅ Purpose

This Business Rule automatically sets the Assignment Group on a Requested Item (RITM) based on the user’s selection in a catalog variable. It also updates the mapped variable value in the sc_item_option_mtom table to ensure data consistency across catalog records.

🔧 Where This Script Runs
Item Details
Table sc_req_item
When Before Insert / Before Update
Script Type Business Rule
Execution Scope Server-side
📌 Prerequisites

For this script to operate correctly:

1️⃣ Catalog Variable exists on the item:

Name → dummy_app_group

Type → Select Box

Possible Values → AppGroup A, AppGroup B, AppGroup C, etc.

2️⃣ Assignment Group sys_ids should be updated to real sys_ids in Production.

3️⃣ The variable that stores reference to the group must be mapped in M2M table:

Name → dummy_group_variable

Type → Reference (sys_user_group)

4️⃣ Assignment Group field must be visible and editable on RITM.

🚀 What the Script Does

✔ Reads catalog variable value selected by requester
✔ Matches the value and determines corresponding Assignment Group
✔ Updates RITM field assignment_group
✔ Updates dummy_group_variable in sc_item_option_mtom table
✔ Displays info/error messages for debugging and validation

🧩 Example Mapping Used in This Script
Catalog Variable Value Assignment Group (Dummy sys_id)
AppGroup A 11111111111111111111111111111111
AppGroup B 22222222222222222222222222222222
AppGroup C 33333333333333333333333333333333

Replace with actual assignment group sys_ids before deployment.

✅ Benefits
Feature Advantage
Automated Group Assignment Eliminates manual errors & delays
Consistency in Catalog Variables Accurate reporting and auditing
Debug-Friendly Messaging Quick validation during testing
🛠️ Deployment Notes

Disable info messages (gs.addInfoMessage) after successful testing

Maintain updates when catalog variable choices expand

Avoid hard-coding by considering future enhancement → mapping object / system properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//Auto-assignment based on application variable selection in catalog
///*
//==============================================================================
// Script: Auto Assignment by Application Group
// Table: sc_req_item | When: Before Insert/Update

// PREREQUISITES ✅
// ------------------------------------------------------------------------------
// 1️⃣ Catalog Variable must exist:
// - Name: dummy_app_group (Select Box)
// - Values: AppGroup A/B/C etc.

// 2️⃣ Assignment Group sys_ids mapping must be updated with real values in PROD.

// 3️⃣ Variable stored in sc_item_option_mtom for sync:
// - Name: dummy_group_variable (Reference: sys_user_group)

// 4️⃣ Assignment Group field must be present on RITM form.

// Summary: Auto-assign Assignment Group based on selected Application Group +
//update associated variable for data consistency.
//==============================================================================
//*/

(function executeRule(current, previous /*null when async*/) {
// Retrieve the application group variable
var appGroupVar = current.variables.dummy_app_group;
var groupSysId = ''; // This will store the dummy sys_id

// Ensure the variable exists before proceeding
if (appGroupVar) {
var appGroupValue = appGroupVar.getDisplayValue(); // Get the display value of the variable

// Match group values and assign dummy group sys_ids
if (appGroupValue === 'AppGroup A') {
groupSysId = '11111111111111111111111111111111';
} else if (appGroupValue === 'AppGroup B') {
groupSysId = '22222222222222222222222222222222';
} else if (appGroupValue === 'AppGroup C') {
groupSysId = '33333333333333333333333333333333';
}

// Update Assignment Group in the RITM
if (groupSysId) {
current.assignment_group = groupSysId; // Set dummy sys_id in Assignment Group
gs.addInfoMessage('Assignment Group updated to sys_id: ' + groupSysId);

// Update the group variable on sc_item_option_mtom table
var grVars = new GlideRecord('sc_item_option_mtom');
grVars.addQuery('request_item', current.sys_id);
grVars.addQuery('sc_item_option.item_option_new.name', 'dummy_group_variable');
grVars.query();
if (grVars.next()) {
grVars.value = groupSysId;
grVars.update();
gs.addInfoMessage('Group variable updated to sys_id: ' + groupSysId);
} else {
gs.addErrorMessage('Group variable not found for the RITM.');
}
} else {
gs.addErrorMessage('No valid Assignment Group found for: ' + appGroupValue);
}
} else {
gs.addErrorMessage('Application group variable is not set.');
}
})(current, previous);
Loading