- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 10:54 AM
Hello everyone,
My team created a select box with dynamic options using a onChange Client Script. I would like to be able to store the selected value in a variable and use it to auto-populate other field. I'm struggling to achieve this, any help provided will be greatly appreciated.
AddOption client script:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 12:20 PM - edited 08-26-2024 12:24 PM
Since kb_article is a reference variable in the Catalog Item, drop the third argument
if (scat == 'metadata_management') {
g_form.setValue('kb_article', 'c8b6a62413f81300004b32228144b06c');
}
If it's still not working as expected, alert on newValue/scat to confirm the value you are using in the if condition is exactly correct.
There's not really a point in assigning newValue to another script variable, so your script could just be
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.setVisible('kb_article', false);
return;
}
g_form.setVisible('kb_article', true);
if (newValue == 'metadata_management') {
g_form.setValue('kb_article', 'c8b6a62413f81300004b32228144b06c');
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 10:58 AM - edited 08-26-2024 11:00 AM
Why are you using the triple equals sign in your if statement? Note sure if that is the problem but I would start there as the rest of your code looks fine.
Edit: Why are you using a script on subcategory? You can just make it depending on category and fill in the depending value field on the subcategory choice list.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 12:01 PM
Quality control checks enforced requested triple equal sign on If statements.
The subcategory list is going to be a lot bigger, (way more categories and subcategories) and must be populated based on "Category" field. That is why we did not created the options directly in the Select Box Variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 11:16 AM
I don't think I'm following. Is this script working to dynamically add options to the subcategory select box? The selected value would be stored in the subcategory variable, so why do you need to store it elsewhere? If you want to populate another variable based on the selected subcategory value, then create an onChange Catalog Client Script when subcategory changes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 12:16 PM
I tried to create a new OnChange Client Script for getting the subcategory value and use it to dynamically display a KB number in a reference field. The first step is get the sub_category value to use it on an If statement. However this is not working.
The new OnChange script is as follows: