From ba1c8369b69e363bbd2151a7b9a717356c16bbe9 Mon Sep 17 00:00:00 2001 From: arigalamani Date: Mon, 27 Oct 2025 00:03:08 +0530 Subject: [PATCH 1/2] Create Readme.md Onchange validation client script --- .../Onchange Validation Client Script/Readme.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Client-Side Components/Client Scripts/Onchange Validation Client Script/Readme.md diff --git a/Client-Side Components/Client Scripts/Onchange Validation Client Script/Readme.md b/Client-Side Components/Client Scripts/Onchange Validation Client Script/Readme.md new file mode 100644 index 0000000000..e12b75ad5f --- /dev/null +++ b/Client-Side Components/Client Scripts/Onchange Validation Client Script/Readme.md @@ -0,0 +1,16 @@ +This client script dynamically controls field visibility, auto-calculates priority, +and validates user input on the Incident form based on category, impact, and urgency — all without using a Script Include. + +it runs whenever the Category field value changes on the form. + +1.Validate form fields before saving (example: block submission if “Impact” or “Urgency” is empty). +2.Auto-calculate “Priority” based on “Impact” and “Urgency.” +3.Hide or show fields depending on “Category.” +4.Dynamically filter “Assignment Group” choices based on “Department.” + +Uses: +Runs when Category changes on the Incident form. +Dynamically shows/hides the Serial Number field. +Auto-calculates Priority purely on the client side (no server calls). +Displays inline error messages or alerts based on user input. +Enforces logic that prevents invalid combinations. From 121806c07f6427947d4fc3fd8843d5fab5254f6a Mon Sep 17 00:00:00 2001 From: arigalamani Date: Mon, 27 Oct 2025 00:04:33 +0530 Subject: [PATCH 2/2] Onchange validation client script Validates the onchange client script based on the category, priority and urgency --- .../onchange_validation_client_script.js | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Client-Side Components/Client Scripts/Onchange Validation Client Script/onchange_validation_client_script.js diff --git a/Client-Side Components/Client Scripts/Onchange Validation Client Script/onchange_validation_client_script.js b/Client-Side Components/Client Scripts/Onchange Validation Client Script/onchange_validation_client_script.js new file mode 100644 index 0000000000..adea300fc5 --- /dev/null +++ b/Client-Side Components/Client Scripts/Onchange Validation Client Script/onchange_validation_client_script.js @@ -0,0 +1,50 @@ +function onChange(control, oldValue, newValue, isLoading, isTemplate) { + if (isLoading || newValue === '') { + return; + } + + // Example: Dynamic behavior when Category changes + var category = g_form.getValue('category'); + var impact = g_form.getValue('impact'); + var urgency = g_form.getValue('urgency'); + + // Hide or show certain fields dynamically + if (category === 'hardware') { + g_form.setVisible('u_serial_number', true); + g_form.setMandatory('u_serial_number', true); + } else { + g_form.setVisible('u_serial_number', false); + g_form.setMandatory('u_serial_number', false); + } + + // Auto-calculate Priority based on Impact & Urgency + // (Client-only logic — no Script Include needed) + var priorityMap = { + '1_1': '1', + '1_2': '2', + '1_3': '3', + '2_1': '2', + '2_2': '3', + '2_3': '4', + '3_1': '3', + '3_2': '4', + '3_3': '5' + }; + + var key = impact + '_' + urgency; + var newPriority = priorityMap[key] || '5'; + g_form.setValue('priority', newPriority); + + // how a dynamic message when conditions are met + if (category === 'hardware' && urgency === '1') { + g_form.showFieldMsg('category', 'Critical hardware issue detected! Escalate immediately.', 'error'); + } else { + g_form.hideFieldMsg('category'); + } + + // Prevent invalid data combination (client-side validation) + if (category === 'software' && impact === '1' && urgency === '1') { + alert('High impact & urgency for software incidents require manager approval before submission.'); + g_form.setValue('state', ''); // Reset state to stop progression + } +}