Client Script to show values based on selection
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2023 05:32 PM
I know this topic has been asked a lot, but I have a specific set of requirements. I cannot use field dependencies because our category choices are used on more than one occassion.
Category field needs to display certain choices based on selection from our Product field, however it is not working.
Current client script setup:
Type: onChange
Field: Product
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(g_form.getDisplayBox('product').value == 'Test Product'){
g_form.clearOptions('category');
g_form.addOption('category','666','Test Category');
}
}
The Product field is a reference field to the cmdb_model:
Table: sn_customerservice_case
Field: product
Type: reference
Reference: cmdb_model
Category field an is out of the box integer field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2023 07:09 PM
Hi @HP8
Can you try with updated line of code.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(g_form.getDisplayValue('product') == 'Test Product'){
g_form.clearOptions('category');
g_form.addOption('category','666','Test Category');
}else {
// add options if value is different
}
}
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2023 08:03 PM - edited 09-25-2023 08:03 PM
Can you try this one