Client Script to update the Choice List on the Subcategory field based on the Company
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2018 08:35 AM
I have a Category of Software and a list of applications defined in the Subcategory. These are configured via Choice List.
I want to remove one application from the Subcategory list when a specific Company is selected.
I have done something similar via an OnChange Client Script based on the Company field but I can't get this to work. This is the script I have....
The sys_id is the correct sys_id for the Company.
Where am I going wrong?
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2018 08:45 AM
Check this in the docs
https://docs.servicenow.com/bundle/kingston-application-development/page/app-store/dev_portal/API_re...
Try with
g_form.removeOption('subcategory', 'Sonata');
Not sure what you are using var subcategory for, could probably be removed.
Also consider to not use a sys_id in a script, it's best practice to store the sys_id in a property and then use gs.getProperty() to get the sys_id from the property.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2018 02:59 AM
This makes the code tidier but does not remove the option from the Choice List. Can you share the syntax for using the gs.getProperty() command?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2018 10:55 AM
hi simonbourne,
can you try with this code,make sure that category and application name should as per your requirement,
but hope this will work for you...
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var software=g_form.getValue('software');
if(software=='software1')
{
g_form.clearOptions('subcatagory');
g_form.addOption('subcatagory','application1','app1');
g_form.addOption('subcatagory','application2','app2');
g_form.addOption('subcatagory','application3','app3');
}
if(software=='software2')
{
g_form.clearOptions('subcatagory');
g_form.addOption('subcatagory','application1','app1');
g_form.addOption('subcatagory','application2','app2');
//g_form.addOption('subcatagory','application3','app3'); if you will not add this it wont be place under it
}
still if you have any dough,reply for same...
if helpful make it correct or helpful!!
Regards,
Varsha.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2018 03:05 AM
Hi,
Is there a chance where a single subcategory should be made visible to 2 or more categories? If NO, you can use dependent field on choice list of Subcategory.
Thanks,
Archana