Want to confirm and g_form.clearOptions does NOT work on a catalog variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2016 10:46 AM
We developing a catalog item with a form which has 2 variables tied to each other.
I'll call them field_1 and field_2. They are both "Select Box" type variables.
The choices in field_1 will determine the options available in field _2.
Since I can't make field_2 dependent on field_1, I'm simulating it with an onchange catalog client script on field_1.
I have a series of if statements to test the value of field_1 against all of its options. See sample of script below.
Given the script, if I select field_1=option_1, and then select field_1=option_2, I end up with the options for BOTH possibilities in field_2.
I tried to add the command g_form.clearOptions('field_2'); but then all options are cleared from field_2 and no options are added.
I can add code to each option to turn add it or remove it, but i was hoping there was a simpler solution.
Example of Catalog Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue == 'environment')
{
alert('line 8');
g_form.removeOption('sub_standard', 'opt2');
g_form.removeOption('sub_standard', 'opt3');
g_form.removeOption('sub_standard', 'opt4');
g_form.removeOption('sub_standard', 'opt5');
g_form.removeOption('sub_standard', 'opt6');
g_form.addOption('sub_standard', 'opt1', 'Option #1');
}
else if (newValue == 'components')
{
alert('line 18');
g_form.addOption('sub_standard', 'opt2', 'Option #2');
g_form.removeOption('sub_standard', 'opt1');
// g_form.removeOption('sub_standard', 'opt2');
g_form.removeOption('sub_standard', 'opt3');
g_form.removeOption('sub_standard', 'opt4');
g_form.removeOption('sub_standard', 'opt5');
g_form.removeOption('sub_standard', 'opt6');
}
else if (newValue == 'monitoring')
{
alert('line 29');
g_form.addOption('sub_standard', 'opt3', 'Option #3');
g_form.removeOption('sub_standard', 'opt1');
g_form.removeOption('sub_standard', 'opt2');
// g_form.removeOption('sub_standard', 'opt3');
g_form.removeOption('sub_standard', 'opt4');
g_form.removeOption('sub_standard', 'opt5');
g_form.removeOption('sub_standard', 'opt6');
}
else if (newValue == 'server_storage_compute')
{
alert('line 40');
g_form.addOption('sub_standard', 'opt4', 'Option #4');
g_form.removeOption('sub_standard', 'opt1');
g_form.removeOption('sub_standard', 'opt2');
g_form.removeOption('sub_standard', 'opt3');
// g_form.removeOption('sub_standard', 'opt4');
g_form.removeOption('sub_standard', 'opt5');
g_form.removeOption('sub_standard', 'opt6');
}
else if (newValue == 'network')
{
alert('line 51');
g_form.addOption('sub_standard', 'opt5', 'Option #5');
g_form.removeOption('sub_standard', 'opt1');
g_form.removeOption('sub_standard', 'opt2');
g_form.removeOption('sub_standard', 'opt3');
g_form.removeOption('sub_standard', 'opt4');
// g_form.removeOption('sub_standard', 'opt5');
g_form.removeOption('sub_standard', 'opt6');
}
else if (newValue == 'unmonitored')
{
alert('line 62');
g_form.addOption('sub_standard', 'opt6', 'Option #6');
g_form.removeOption('sub_standard', 'opt1');
g_form.removeOption('sub_standard', 'opt2');
g_form.removeOption('sub_standard', 'opt3');
g_form.removeOption('sub_standard', 'opt4');
g_form.removeOption('sub_standard', 'opt5');
// g_form.removeOption('sub_standard', 'opt6');
}
else
{
alert ('program error 35');
}
}
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2016 06:20 PM
Hi Steve,
What version is your instance?
Are you trying to do this via the Service Portal or the normal Service Catalog view?
I've run into a similar problem on Helsinki Patch 2 and Patch 5....
I've raised a HI ticket for them to investigate.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2016 10:45 PM
I would say add the clearOptions method at the start of the function so it gets executed first irrespective of the choice being selected. Only do the addOption in the respective 'if' conditions.
Give it a try and let me know if that works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2016 11:07 PM
Hi Steve,
Just after your alert lines (alert('line 8'); alert('line 18'); alert('line 29'); etc etc.), please use the clear option code g_form.clearOptions('field_2'); and then use the add option line. Means rest of your code would be the same. Just a try !
Let us know your results.
Thanks,
Arnab