diff --git a/Client-Side Components/Client Scripts/validate Interaction if it is an FCR(First Call Resolution)/readme.md b/Client-Side Components/Client Scripts/validate Interaction if it is an FCR(First Call Resolution)/readme.md new file mode 100644 index 0000000000..a66f646ec5 --- /dev/null +++ b/Client-Side Components/Client Scripts/validate Interaction if it is an FCR(First Call Resolution)/readme.md @@ -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 diff --git a/Client-Side Components/Client Scripts/validate Interaction if it is an FCR(First Call Resolution)/script.js b/Client-Side Components/Client Scripts/validate Interaction if it is an FCR(First Call Resolution)/script.js new file mode 100644 index 0000000000..1b43c255d2 --- /dev/null +++ b/Client-Side Components/Client Scripts/validate Interaction if it is an FCR(First Call Resolution)/script.js @@ -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 +} diff --git a/Server-Side Components/Business Rules/Auto-assignment based on variable selection in catalog/readme.md b/Server-Side Components/Business Rules/Auto-assignment based on variable selection in catalog/readme.md new file mode 100644 index 0000000000..2dfa32a15c --- /dev/null +++ b/Server-Side Components/Business Rules/Auto-assignment based on variable selection in catalog/readme.md @@ -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 diff --git a/Server-Side Components/Business Rules/Auto-assignment based on variable selection in catalog/script.js b/Server-Side Components/Business Rules/Auto-assignment based on variable selection in catalog/script.js new file mode 100644 index 0000000000..0ac4b4dda8 --- /dev/null +++ b/Server-Side Components/Business Rules/Auto-assignment based on variable selection in catalog/script.js @@ -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);