- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2023 01:18 AM
Hi , I have a requirement to have only specific values on dropdown of subcategory when a specific category is selected
i have created a client script for that :
But when i am selecting for the first time it is working fine but for the second time , it is giving me first selection values and latest selection values both in subcategory dropdown.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue == 'IAM') {
g_form.addOption('subcategory', 'Add permission', 'Add permission');
g_form.addOption('subcategory', 'Create new policy', 'Create new policy');
g_form.addOption('subcategory', 'Roles', 'Roles');
g_form.addOption('subcategory', 'Policies', 'Policies');
g_form.addOption('subcategory', 'Assume role', 'Assume role');
g_form.addOption('subcategory', 'Other', 'Other');
}
if (newValue == 'VM Instances') {
g_form.addOption('subcategory', 'Login issue', 'Login issue');
g_form.addOption('subcategory', 'Permissions ', 'Permissions ');
g_form.addOption('subcategory', 'Images', 'Images');
g_form.addOption('subcategory', 'Manage Instance group (MIG) statfull', 'Manage Instance group (MIG) statfull');
g_form.addOption('subcategory', 'Manage Instance group (MIG) statless', 'Manage Instance group (MIG) statless');
g_form.addOption('subcategory', 'Unmanage Instance group (UMIG)', 'Unmanage Instance group (UMIG)');
g_form.addOption('subcategory', 'Images', 'Images');
g_form.addOption('subcategory', 'Filestore', 'Filestore');
g_form.addOption('subcategory', 'Reserved static IP', 'Reserved static IP');
g_form.addOption('subcategory', 'Instances', 'Instances');
g_form.addOption('subcategory', 'Load Balancers', 'Load Balancers');
g_form.addOption('subcategory', 'Firewall rules', 'Firewall rules');
g_form.addOption('subcategory', 'Snapshots ', 'Snapshots ');
g_form.addOption('subcategory', 'disks', 'disks');
g_form.addOption('subcategory', 'Agents', 'Agents');
g_form.addOption('subcategory', 'Machine type', 'Machine type');
g_form.addOption('subcategory', 'Tags', 'Tags');
g_form.addOption('subcategory', 'Status', 'Status');
g_form.addOption('subcategory', 'Other ', 'Other ');
}
if (newValue == 'GKE') {
g_form.addOption('subcategory', 'Permissions ', 'Permissions ');
g_form.addOption('subcategory', 'Other ', 'Other ');
}
if (newValue == 'Cloud Storage') {
g_form.addOption('subcategory', 'Permissions ', 'Permissions ');
g_form.addOption('subcategory', 'Bucket', 'Bucket');
g_form.addOption('subcategory', 'Other ', 'Other ');
}
if (newValue == 'Cloud DNS') {
g_form.addOption('subcategory', 'Permissions ', 'Permissions ');
g_form.addOption('subcategory', 'Firewall rules', 'Firewall rules');
g_form.addOption('subcategory', 'Other ', 'Other ');
}
if (newValue == 'Cloud Function') {
g_form.addOption('subcategory', 'Add permission', 'Add permission');
g_form.addOption('subcategory', 'Other ', 'Other ');
}
if (newValue == 'VPC') {
g_form.addOption('subcategory', 'Create a new VPC', 'Create a new VPC');
g_form.addOption('subcategory', 'Add subnets', 'Add subnets');
g_form.addOption('subcategory', 'Other ', 'Other ');
}
if (newValue == 'logging & Monitoring') {
g_form.addOption('subcategory', 'Alarms ', 'Alarms ');
g_form.addOption('subcategory', 'Other ', 'Other ');
}
if (newValue == 'Other') {
g_form.addOption('subcategory', 'Permissions ', 'Permissions ');
g_form.addOption('subcategory', 'Other ', 'Other ');
}
//Type appropriate comment here, and begin script below
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2023 03:55 AM
Hi @avinashdubey103
The easiest way to get this done is
Create dependency between category & subcategory
Go to the dictionary entry of the 'subcategory' field, navigate to the choices, personalise list view to add the dependent value--> add the 'value' of Category
Let me know if this works and mark the answer helpful
Thanks
Sails
ServiceNow Consultant
United Kingdom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2023 01:38 AM
Please try the below script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (newValue == 'IAM') {
g_form.clearValue('subcategory');
g_form.addOption('subcategory', 'Add permission', 'Add permission');
g_form.addOption('subcategory', 'Create new policy', 'Create new policy');
g_form.addOption('subcategory', 'Roles', 'Roles');
g_form.addOption('subcategory', 'Policies', 'Policies');
g_form.addOption('subcategory', 'Assume role', 'Assume role');
g_form.addOption('subcategory', 'Other', 'Other');
}
if (newValue == 'VM Instances') {
g_form.clearValue('subcategory');
g_form.addOption('subcategory', 'Login issue', 'Login issue');
g_form.addOption('subcategory', 'Permissions ', 'Permissions ');
g_form.addOption('subcategory', 'Images', 'Images');
g_form.addOption('subcategory', 'Manage Instance group (MIG) statfull', 'Manage Instance group (MIG) statfull');
g_form.addOption('subcategory', 'Manage Instance group (MIG) statless', 'Manage Instance group (MIG) statless');
g_form.addOption('subcategory', 'Unmanage Instance group (UMIG)', 'Unmanage Instance group (UMIG)');
g_form.addOption('subcategory', 'Images', 'Images');
g_form.addOption('subcategory', 'Filestore', 'Filestore');
g_form.addOption('subcategory', 'Reserved static IP', 'Reserved static IP');
g_form.addOption('subcategory', 'Instances', 'Instances');
g_form.addOption('subcategory', 'Load Balancers', 'Load Balancers');
g_form.addOption('subcategory', 'Firewall rules', 'Firewall rules');
g_form.addOption('subcategory', 'Snapshots ', 'Snapshots ');
g_form.addOption('subcategory', 'disks', 'disks');
g_form.addOption('subcategory', 'Agents', 'Agents');
g_form.addOption('subcategory', 'Machine type', 'Machine type');
g_form.addOption('subcategory', 'Tags', 'Tags');
g_form.addOption('subcategory', 'Status', 'Status');
g_form.addOption('subcategory', 'Other ', 'Other ');
}
if (newValue == 'GKE') {
g_form.clearValue('subcategory');
g_form.addOption('subcategory', 'Permissions ', 'Permissions ');
g_form.addOption('subcategory', 'Other ', 'Other ');
}
if (newValue == 'Cloud Storage') {
g_form.addOption('subcategory', 'Permissions ', 'Permissions ');
g_form.addOption('subcategory', 'Bucket', 'Bucket');
g_form.addOption('subcategory', 'Other ', 'Other ');
}
if (newValue == 'Cloud DNS') {
g_form.addOption('subcategory', 'Permissions ', 'Permissions ');
g_form.addOption('subcategory', 'Firewall rules', 'Firewall rules');
g_form.addOption('subcategory', 'Other ', 'Other ');
}
if (newValue == 'Cloud Function') {
g_form.clearValue('subcategory');
g_form.addOption('subcategory', 'Add permission', 'Add permission');
g_form.addOption('subcategory', 'Other ', 'Other ');
}
if (newValue == 'VPC') {
g_form.clearValue('subcategory');
g_form.addOption('subcategory', 'Create a new VPC', 'Create a new VPC');
g_form.addOption('subcategory', 'Add subnets', 'Add subnets');
g_form.addOption('subcategory', 'Other ', 'Other ');
}
if (newValue == 'logging & Monitoring') {
g_form.addOption('subcategory', 'Alarms ', 'Alarms ');
g_form.addOption('subcategory', 'Other ', 'Other ');
}
if (newValue == 'Other') {
g_form.clearValue('subcategory');
g_form.addOption('subcategory', 'Permissions ', 'Permissions ');
g_form.addOption('subcategory', 'Other ', 'Other ');
}
//Type appropriate comment here, and begin script below
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2023 02:08 AM
hi , still facing the same issue after updating the code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2023 03:55 AM
Hi @avinashdubey103
The easiest way to get this done is
Create dependency between category & subcategory
Go to the dictionary entry of the 'subcategory' field, navigate to the choices, personalise list view to add the dependent value--> add the 'value' of Category
Let me know if this works and mark the answer helpful
Thanks
Sails
ServiceNow Consultant
United Kingdom