- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2017 07:04 PM
Hi All,
I am trying to develop a catalog client script for a Service Portal Item.
Below is the code I am using:
--------
var cat = newValue;
g_form.clearOptions('subcategory');
var choice = new GlideRecord('sys_choice');
choice.addQuery('dependent_value', cat);
choice.query(function(choice){
while(choice.next()){
g_form.addOption('subcategory', choice.value, choice.value);
}
});
--------
I want to dynamically populate subcategory based on selected category.
And every time, category changes, it should change the list of available subcategory.
g_form.clearOptions('subcategory'); , does the job but it also makes the default '--None--' un-selectable.
I want to remove all options except default '--None--'.
g_form.getControl().options.length =1;, was doing the same job easily for other catalog items but this doesn't work for Service Catalog.
Can someone, help me to fix this issue.
Thanks
Shihab
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2017 11:17 PM
Hi Shibab,
addOption accepts the choiceIndex which you can use to specify the order. This will solve your first issue.
void addOption(fieldName, choiceValue, choiceLabel, [choiceIndex]))
- Adds a choice to a choice list field. If the index is not specified, the choice parameter is added to the end of the list.
- Optional: Use the index field to specify a particular place in the list.
- Parameters:
- fieldName - specifies the field.
- choiceValue - the value stored in the database.
- choiceLabel - the value displayed.
- choiceIndex (optional) - order of choice in the list.
- Returns:
- void
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2017 07:16 PM
Hi Shihab,
I might be missing something here, but just wanted to ask why cant you just add an option at the end of the while with addOption(('subcategory', '', '--None --')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2017 07:41 PM
Hi Srinivas,
Firstly adding it after the while, brings the none at the end, which doesn't look good.
And then if I add this before the while, then it keeps on adding more 'none', everytime the script runs. Don't know why.
Moreover, my issue is not that default 'none' gets removed, in my case default 'none' is showing but not selectable.
So if I add another none, using addOption then it gives me 2 'none' in the list, which I don't want.
Can you please advise some other option?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2017 11:17 PM
Hi Shibab,
addOption accepts the choiceIndex which you can use to specify the order. This will solve your first issue.
void addOption(fieldName, choiceValue, choiceLabel, [choiceIndex]))
- Adds a choice to a choice list field. If the index is not specified, the choice parameter is added to the end of the list.
- Optional: Use the index field to specify a particular place in the list.
- Parameters:
- fieldName - specifies the field.
- choiceValue - the value stored in the database.
- choiceLabel - the value displayed.
- choiceIndex (optional) - order of choice in the list.
- Returns:
- void
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2017 08:58 PM
Thanks mate. That solved the issue along with a UI policy.