Skip to content
Merged
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,20 @@
## 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.

**How to Use:**
1. **Modify the table name** in the `switchView` function to match your target table:
```javascript
switchView("section", "<your_table_name>", targetView);
2. **Modify the view mapping**
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* 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 {
// Here for example the table name is incident
switchView("section", "incident", targetView);
} catch (e) {
console.error("View switch failed: ", e);
}
}
}
Loading