- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2023 06:03 AM - edited 08-25-2023 06:11 AM
Good Day Team,
I have a Select Box (Items)with 40 different options (dont) ask my why. the requirement i have is to narrow the list based on another field (Field 1)
so what i done is created 2 catalog script
script 1 I want to make AddOptions VISIABLE when "Item = Hardware" and Hide all other options from the list
script 2 I want to hide the Door,cabinet,Desk and bring Visiable Memory,Drive,Motherboard when (Item) = "Computer"
Im using a onChange Script to do this and it's pointing at Item and in the code i have
SCRIPT 1
function onChange(control, oldValue, newValue, isLoading) {
// if (isLoading || newValue == '') {
return;
}
if(g_form.getValue('Item')=='Hardware'){
g_form.addOption('Selection', 'Door');
g_form.addOption('Selection', 'Cabinet');
g_form.addOption('Selection', 'Desk');
g_form.removeOption('Selection', 'memory');
g_form.removeOption('Selection', 'drive');
g_form.removeOption('Selection', 'Motherboard');
}}
SCRIPT 2
function onChange(control, oldValue, newValue, isLoading) {
// if (isLoading || newValue == '') {
return;
}
if(g_form.getValue('Item')=='Hardware'){
g_form.removeOption('Selection', 'Door');
g_form.removeOption('Selection', 'Cabinet');
g_form.removeOption('Selection', 'Desk');
g_form.addOption('Selection', 'memory');
g_form.addOption('Selection', 'drive');
g_form.addOption('Selection', 'Motherboard');
}}
Script 1 runs showing only the items with the addOption..
Script 2 does not show anything but --NONE--
Can someone set me straight
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2023 06:28 AM
Hello @Walter Toney
You can use only one OnChange Catalog Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if ( newValue == "Hardware" ){
g_form.addOption('Selection', 'Door');
g_form.addOption('Selection', 'Cabinet');
g_form.addOption('Selection', 'Desk');
g_form.removeOption('Selection', 'memory');
g_form.removeOption('Selection', 'drive');
g_form.removeOption('Selection', 'Motherboard');
}
else if ( newValue == "Computer" ){
g_form.addOption('Selection', 'memory');
g_form.addOption('Selection', 'drive');
g_form.addOption('Selection', 'Motherboard');
g_form.removeOption('Selection', 'Door');
g_form.removeOption('Selection', 'Cabinet');
g_form.removeOption('Selection', 'Desk');
}
}
Help others to find a correct solution by marking the appropriate response as correct answer and helpful.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2023 06:17 AM
Hi @Walter Toney ,
Please change the if(g_form.getValue('Item')=='Hardware'){
in script SCRIPT 2
if(g_form.getValue('Item')=='Computer'){
Please Mark Helpful
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2023 06:28 AM
Hello @Walter Toney
You can use only one OnChange Catalog Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if ( newValue == "Hardware" ){
g_form.addOption('Selection', 'Door');
g_form.addOption('Selection', 'Cabinet');
g_form.addOption('Selection', 'Desk');
g_form.removeOption('Selection', 'memory');
g_form.removeOption('Selection', 'drive');
g_form.removeOption('Selection', 'Motherboard');
}
else if ( newValue == "Computer" ){
g_form.addOption('Selection', 'memory');
g_form.addOption('Selection', 'drive');
g_form.addOption('Selection', 'Motherboard');
g_form.removeOption('Selection', 'Door');
g_form.removeOption('Selection', 'Cabinet');
g_form.removeOption('Selection', 'Desk');
}
}
Help others to find a correct solution by marking the appropriate response as correct answer and helpful.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2023 07:11 AM
In your both if condition ,first clear all options and then add the required options
if(g_form.getValue('Item')=='Hardware'){
g_form.clearOptions('Selection');
g_form.addOption('Selection', 'Door');
g_form.addOption('Selection', 'Cabinet');
g_form.addOption('Selection', 'Desk');
}}
if(g_form.getValue('Item')=='Hardware'){
g_form.clearOptions('Selection');
g_form.addOption('Selection', 'memory');
g_form.addOption('Selection', 'drive');
g_form.addOption('Selection', 'Motherboard');
}}
you can add index as well for sequencing as below
g_form.addOption('Selection', 'memory',1);//1,2,3 etc
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful based on the Impact
Thanks,
Manjusha Bangale