None in Catalog Client Script After clearOption()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2017 08:41 AM
Hi Experts,
I am trying to dynamically get "Subcategory" based on "Category" from incident table using catalog client script for Service Portal.
Every time category changes the subcategory getting populated normally. No issues.
But the issue is that getting --None-- value only by the first time category change.
Please find my script below,
Name: Catalog Client Script
function onChange(control, oldValue, newValue, isLoading) {
if(newValue == ''"){
g_form.clearOptions('subcategory');
g_form.clearOptions('u_subcategory_2');
}
if(newValue == oldValue){
return;
}
g_form.clearOptions('subcategory');
g_form.addOption('subcategory', 'none', '-- None --',0);
g_form.setValue('subcategory', 'none', '-- None --');
var gp = new GlideRecord('sys_choice');
gp.addQuery('name', 'incident');
gp.addQuery('dependent_value', newValue);
gp.addQuery('element', 'subcategory');
gp.addQuery('inactive', 'false');
gp.query(function(gp) {
while(gp.next()){
g_form.addOption('subcategory', gp.value, gp.label,gp.sequence);
}
g_form.addOption('subcategory', 'none', '-- None --',0);
g_form.setValue('subcategory', 'none', '-- None --');
});
}
Please help me to solve the issue.
Thanks in Advance.
Regards,
Anna.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2017 08:25 AM
Try one other thing...remove the setValue and the sequence on all of the addOptions. See what happens.
Also, SS your code and the form this is happening on.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2019 09:18 AM
This worked fine as an onChange script for the category field:
function onChange(control, oldValue, newValue, isLoading) {
if(newValue == oldValue){ return; }
//remove all items from subcat drop down to start
// Used the g_form.clearOptions() function instead of g_form.removeOption() function
//alert('cat=' + newValue);
g_form.clearOptions('subcategory');
//build a new list of dependent options
var gp = new GlideRecord('sys_choice');
gp.addQuery('name', 'incident'); // the field label for this says "table" but its "name"
gp.addQuery('element', 'subcategory');
gp.addQuery('dependent_value', newValue);
gp.query();
while(gp.next())
{
//alert('value=' + gp.value);
g_form.addOption('subcategory', gp.value, gp.label);
}
g_form.addOption('subcategory', '' , '-- None --'); // <--------------------
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2019 06:49 AM
I have used Glide Ajax to get subcategory values based on category. That solved my issue.
Thanks for all for your wonderful response.