UI Policy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday
I'm having trouble applying a simple display rule via Catalog UI Policy.
Rule: When selecting field A, a subsequent field is displayed with 4 items (which is the total number of items displayed by the field), but when selecting field B, the subsequent field should only show 3 items, hiding only 1.
What I've tried so far:
1st. Create rules using best practices by adding AND and OR as field conditions, e.g.:
u_name > is > A
u_name_test > in one of > 1,2,3,4
+ action = u_name_test (action correctly declared for field display)
u_name > is > B
u_name_test > in one of > 1,2,3
+ action = u_name_test (action correctly declared for field display)
2nd. Via the UI Policy script itself:
UI Policy condition -
u_name > is > A
Execute if true:
g_form.clearOptions('u_name_test'); g_form.addOption(''); g_form.removeOption('); execute if false: g_form.clearOptions('u_name_test'); g_form.addOption(''); ...
Could someone tell me if there have been any updates from the new version of the instance, Zurich version? Does anyone have a solution to help me?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday
g_form.clearOptions + g_form.addOption, instead of trying to remove one item, re-add all necessary items every time the condition changes. This is the most reliable way to handle dynamic choice lists in Catalog UI Policies.- UI Policy 1 (Condition: u_name is A)
- Execute if True Script:
g_form.clearOptions('u_name_test'); g_form.addOption('u_name_test', '1', 'Item 1'); g_form.addOption('u_name_test', '2', 'Item 2'); g_form.addOption('u_name_test', '3', 'Item 3'); g_form.addOption('u_name_test', '4', 'Item 4');
- Execute if True Script:
- UI Policy 2 (Condition: u_name is B)
- Execute if True Script:
g_form.clearOptions('u_name_test'); g_form.addOption('u_name_test', '1', 'Item 1'); g_form.addOption('u_name_test', '2', 'Item 2'); g_form.addOption('u_name_test', '3', 'Item 3');
- Execute if True Script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday
Hi @Polyanna Silva ,
you can try the below code :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || !newValue) {
return;
}
// Clear existing options
g_form.clearOptions('u_name_test');
// Optional: add empty option
g_form.addOption('u_name_test', '', '-- Select --');
if (newValue == 'A') {
// Show all 4 options
g_form.addOption('u_name_test', '1', 'Option 1');
g_form.addOption('u_name_test', '2', 'Option 2');
g_form.addOption('u_name_test', '3', 'Option 3');
g_form.addOption('u_name_test', '4', 'Option 4');
}
if (newValue == 'B') {
// Show only 3 options
g_form.addOption('u_name_test', '1', 'Option 1');
g_form.addOption('u_name_test', '2', 'Option 2');
g_form.addOption('u_name_test', '3', 'Option 3');
}
}
Sandeep Dutta
Please mark the answer correct & Helpful, if i could help you.
