- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2015 06:44 AM
Hi All!
I am a bit struggling with a client script, and was thinking maybe someone could help me out? I have a field called 'Primary Cause' which has choices of Hardware, Infra Software, Business App, etc., and another field called 'Primary Cause Subcategory' which has choices of Legacy, Known issue, CI error, Capacity etc. My goal is to display just certain choices in 'Primary Cause Subcategory' based on the choice selected in 'Primary Cause'. For example:
--- If Primary Cause of Hardware is selected then only Legacy and CI error choices would be displayed in Primary Cause Subcategory (other choices should not be showing)
--- If Primary Cause of Infra Software was selected then only Known issue, CI error, Capacity choices should be diplayed (other choiuces should be hiden)
--- ...and so on.
I currently have onChange client script for Primary cause (see below), but it does not hide other value that should not be displayed. May I kindly ask someone to help me, provide tips how to achieve desired state?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
//This script displays primary cause subcategories based on primary cause
var causeType = g_form.getValue('u_primary_cause');
if (causeType == 'Hardware') {
g_form.addOption('u_primary_cause_subcategory', 'Legacy', 'Legacy');
g_form.addOption('u_primary_cause_subcategory', 'Known error', 'Known error');
}
}
Any suggestions are greatly appreciated!
Thank you,
Kamile
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2015 06:59 AM
Hi Kamile,
There are multiple ways you could solve this.
1. You could edit the "Primary Cause Sub Category" field via Personalize Dictionary and identify the Primary Cause field as the Dependent field: https://wiki.servicenow.com/index.php?title=Customizing_Choice_List_Options#Defining_Options_for_Cho...
2. In your client script you could try to use the g_form.removeOption() function to remove from the list the options you no longer want displayed. This approach would require more coding than approach 1 above. http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#removeOption
I hope that helps.
Mike

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2015 06:51 AM
This article may be of help to you Hiding field value dependent on another field value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2015 06:59 AM
Hi Kamile,
There are multiple ways you could solve this.
1. You could edit the "Primary Cause Sub Category" field via Personalize Dictionary and identify the Primary Cause field as the Dependent field: https://wiki.servicenow.com/index.php?title=Customizing_Choice_List_Options#Defining_Options_for_Cho...
2. In your client script you could try to use the g_form.removeOption() function to remove from the list the options you no longer want displayed. This approach would require more coding than approach 1 above. http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#removeOption
I hope that helps.
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2015 07:11 AM
Thanks for the help Michael! I used optio 1 and it works great.