- 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 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 01:11 PM
I replicated the scripts on my personal instance and it works, Not sure why is not working in my company's DEV instance. Probably some Knowledge DB access or ACL.
Thanks for the advise. I really appreciate your support