- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2019 01:24 PM
Hello,
I have an OnChange Client Script I'm using to show/hide choices on Select Box variable based on the choice selection of another Select Box variable. When choices are shown they are not in the order specified in the script or in the variable. How can I control the display order?
My script:
-------------------------------------------------------------------------------------
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(newValue == 'var_1' || newValue == 'var_2') {
g_form.removeOption('var_3', 'choice_1' );
}else{
g_form.addOption('var_3', 'choice_1', 'Choice1' );
g_form.addOption('var_3', 'choice_2', 'Choice2' );
}
}
-------------------------------------------------------------------------------------
I would like Choice1 to be displayed first in the Select Box. However, Choice2 is listed first.
Thanks!
Mike
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- 36,333 Views

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2019 02:00 PM
Hi, you must also add an "index" number for placement.
They do not simply order the way you have them lined out here, you must then add a 1 or 2 or 3, etc. for placement.
Like so:
g_form.addOption('var_3', 'choice_1', 'Choice1', 1);
g_form.addOption('var_3', 'choice_2', 'Choice2', 2);
Reference SN doc for more information: https://developer.servicenow.com/app.do#!/api_doc?v=newyork&id=r_GlideformAddOption_String_String_St...
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2019 02:00 PM
Hi, you must also add an "index" number for placement.
They do not simply order the way you have them lined out here, you must then add a 1 or 2 or 3, etc. for placement.
Like so:
g_form.addOption('var_3', 'choice_1', 'Choice1', 1);
g_form.addOption('var_3', 'choice_2', 'Choice2', 2);
Reference SN doc for more information: https://developer.servicenow.com/app.do#!/api_doc?v=newyork&id=r_GlideformAddOption_String_String_St...
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2019 05:35 AM
Perfection, thanks Allen!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2021 12:35 AM
Hi
g_form.addOption('Job_code',rec.value, rec.label);
Kindly help how can we replace the code in such case.
Thanks ,
Pooja