Skip to content

Commit b4c8a83

Browse files
Create dynamic-form-view-onchange.js
Add the code
1 parent b840e84 commit b4c8a83

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* dynamic-form-view-onchange.js
3+
*
4+
* Dynamically switches the form view automatically depending on the value of a specific field.
5+
* Example: If Category = Hardware → switch to ess view.
6+
* Extendable by modifying the mapping object for different fields/values.
7+
*
8+
*/
9+
10+
function onChange(control, oldValue, newValue, isLoading) {
11+
if (isLoading || !newValue) {
12+
return;
13+
}
14+
15+
// Field value → view name mapping
16+
var viewMapping = {
17+
"hardware": "ess",
18+
"software": "itil",
19+
"network": "support"
20+
};
21+
22+
var fieldValue = newValue.toLowerCase();
23+
var targetView = viewMapping[fieldValue];
24+
25+
if (targetView) {
26+
try {
27+
switchView("section", "incident", targetView);
28+
} catch (e) {
29+
console.error("View switch failed: ", e);
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)