From b840e84eb5e16f87258a59321ba5eca2fc944263 Mon Sep 17 00:00:00 2001 From: juhikumarimodi6 <71226446+juhikumarimodi6@users.noreply.github.com> Date: Thu, 2 Oct 2025 09:16:18 +0530 Subject: [PATCH 1/4] Create README.md --- .../README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Client-Side Components/Client Scripts/Dynamically Switch Form View Based on Field Value/README.md diff --git a/Client-Side Components/Client Scripts/Dynamically Switch Form View Based on Field Value/README.md b/Client-Side Components/Client Scripts/Dynamically Switch Form View Based on Field Value/README.md new file mode 100644 index 0000000000..45747635c9 --- /dev/null +++ b/Client-Side Components/Client Scripts/Dynamically Switch Form View Based on Field Value/README.md @@ -0,0 +1,14 @@ +## Dynamically Switch Form View Based on Field Value + +This client script demonstrates how to **automatically switch form views** based on the value of a field. + +**Use case:** +For example, if the **Category** field is set to *Hardware*, the form view switches to **ess**. +You can extend this by updating the mapping object to support additional fields and values (e.g., *Software → itil*, *Network → support*). + +**Benefit:** +Improves user experience by guiding users to the **most relevant form view**, ensuring the right fields are shown for the right scenario. + +**Test:** +- Change the **Category** field to *Hardware* → Form view should switch to **ess**. +- Update mapping to add new conditions (e.g., *Software → itil*) and verify the view switches accordingly. From b4c8a83dca7898083ff902b02fb97996ace6aa58 Mon Sep 17 00:00:00 2001 From: juhikumarimodi6 <71226446+juhikumarimodi6@users.noreply.github.com> Date: Thu, 2 Oct 2025 09:17:13 +0530 Subject: [PATCH 2/4] Create dynamic-form-view-onchange.js Add the code --- .../dynamic-form-view-onchange.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Client-Side Components/Client Scripts/Dynamically Switch Form View Based on Field Value/dynamic-form-view-onchange.js diff --git a/Client-Side Components/Client Scripts/Dynamically Switch Form View Based on Field Value/dynamic-form-view-onchange.js b/Client-Side Components/Client Scripts/Dynamically Switch Form View Based on Field Value/dynamic-form-view-onchange.js new file mode 100644 index 0000000000..f76a9de617 --- /dev/null +++ b/Client-Side Components/Client Scripts/Dynamically Switch Form View Based on Field Value/dynamic-form-view-onchange.js @@ -0,0 +1,32 @@ +/** + * dynamic-form-view-onchange.js + * + * Dynamically switches the form view automatically depending on the value of a specific field. + * Example: If Category = Hardware → switch to ess view. + * Extendable by modifying the mapping object for different fields/values. + * + */ + +function onChange(control, oldValue, newValue, isLoading) { + if (isLoading || !newValue) { + return; + } + + // Field value → view name mapping + var viewMapping = { + "hardware": "ess", + "software": "itil", + "network": "support" + }; + + var fieldValue = newValue.toLowerCase(); + var targetView = viewMapping[fieldValue]; + + if (targetView) { + try { + switchView("section", "incident", targetView); + } catch (e) { + console.error("View switch failed: ", e); + } + } +} From add91c72be6c55ce267425d6fe2b077d75e06d8c Mon Sep 17 00:00:00 2001 From: juhikumarimodi6 <71226446+juhikumarimodi6@users.noreply.github.com> Date: Thu, 2 Oct 2025 09:19:04 +0530 Subject: [PATCH 3/4] Update dynamic-form-view-onchange.js --- .../dynamic-form-view-onchange.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Client-Side Components/Client Scripts/Dynamically Switch Form View Based on Field Value/dynamic-form-view-onchange.js b/Client-Side Components/Client Scripts/Dynamically Switch Form View Based on Field Value/dynamic-form-view-onchange.js index f76a9de617..07e32f6441 100644 --- a/Client-Side Components/Client Scripts/Dynamically Switch Form View Based on Field Value/dynamic-form-view-onchange.js +++ b/Client-Side Components/Client Scripts/Dynamically Switch Form View Based on Field Value/dynamic-form-view-onchange.js @@ -24,6 +24,7 @@ function onChange(control, oldValue, newValue, isLoading) { if (targetView) { try { + // Here for example the table name is incident switchView("section", "incident", targetView); } catch (e) { console.error("View switch failed: ", e); From 6c6887db8b85549ca6d83e0c9e4681a8dccd106b Mon Sep 17 00:00:00 2001 From: juhikumarimodi6 <71226446+juhikumarimodi6@users.noreply.github.com> Date: Thu, 2 Oct 2025 09:27:06 +0530 Subject: [PATCH 4/4] Update README.md --- .../README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Client-Side Components/Client Scripts/Dynamically Switch Form View Based on Field Value/README.md b/Client-Side Components/Client Scripts/Dynamically Switch Form View Based on Field Value/README.md index 45747635c9..3b22ef62bf 100644 --- a/Client-Side Components/Client Scripts/Dynamically Switch Form View Based on Field Value/README.md +++ b/Client-Side Components/Client Scripts/Dynamically Switch Form View Based on Field Value/README.md @@ -12,3 +12,9 @@ Improves user experience by guiding users to the **most relevant form view**, en **Test:** - Change the **Category** field to *Hardware* → Form view should switch to **ess**. - Update mapping to add new conditions (e.g., *Software → itil*) and verify the view switches accordingly. + +**How to Use:** +1. **Modify the table name** in the `switchView` function to match your target table: + ```javascript + switchView("section", "", targetView); +2. **Modify the view mapping**