Not Able To Remove An Option Using Client Scripts When There Is A Dependent Field. How To Do That?SummaryNot Able To Remove An Option Using Client Scripts When There Is A Dependent Field. How To Do That? Scenario: 1. You have an incident record2. On that, you have a category field With values, like: Software, Hardware, Network 3. You have a subcategory field that is dependent of the category field Software: (Email / Operating System)Hardware: (CPU / Desk / Keyboard)Network: (DHCP / DNS / VPN) 4. You need to remove a value from the subcategory when a specific category is selected Remove subcategory email option when software category is selected When you use a dependent field, this cannot be done and the reason for that is because the client scripts are called first and the dependent logic is in place after that moving all the values back into the field. InstructionsYou can use this workaround: 1. Create a script include to simulate the dependent values with: Active: Checked Client callable: Checked Protection policy: None Script: var fetchChoiceValues = Class.create(); fetchChoiceValues.prototype = Object.extendsObject(AbstractAjaxProcessor, { fetch: function() { var results = [], lang = gs.getSession().getUser().getLanguage(), choiceTable = 'sys_choice', tgtFld = this.getParameter( 'sysparm_tgt_fld' ), tgtTbl = this.getParameter( 'sysparm_tgt_tbl' ), dpnVal = this.getParameter( 'sysparm_dpn_val' ) || false; // Fetch choice records (this script assumes the choice table is sys_choice) var gr = new GlideRecord( choiceTable ); gr.addEncodedQuery( 'name=' + tgtTbl + '^element=' + tgtFld + '^inactive=false^language=' + lang ); // Optional dependent value if ( dpnVal ) gr.addQuery( 'dependent_value', dpnVal ); gr.orderBy( 'sequence' ); gr.orderBy( 'label' ); gr.query(); while( gr.next() ) { results.push( { label: gr.label.toString(), value: gr.value.toString(), seq: gr.sequence.toString() }); } var resp = this.newItem( 'result' ); resp.setAttribute( 'choices', JSON.stringify( results )); }, type: 'fetchChoiceValues' }); 2. Create a onLoad client script to load the data with Isolate script: Checked Table: incident Active: Checked Global: Checked Type: onLoad UI Type: All Script: function onLoad() { // Fetch the field choices from the server var ga = new GlideAjax( 'fetchChoiceValues' ); ga.addParam( 'sysparm_name', 'fetch' ); ga.addParam( 'sysparm_tgt_fld', 'subcategory' ); ga.addParam( 'sysparm_tgt_tbl', 'incident' ); ga.addParam( 'sysparm_dpn_val', ( g_form.getValue( 'category' ) || 'inquiry' )); ga.getXML( function( res ) { // Parse the server response var result = res.responseXML.getElementsByTagName( 'result' ); var choices = JSON.parse( result[0].getAttribute( 'choices' )); // Clear the existing choices g_form.clearOptions( 'subcategory' ); // Populate the new choices for ( var i = 0, cl = choices.length; i < cl; ++i ) g_form.addOption( 'subcategory', choices[i].value, choices[i].label ); }); } 3. Create an onChange client script to handed the logic to remove the entry when the category is selected with Isolate script: Checked Active: Checked Table: incident Global: Checked Type: onChange UI Type: All Field name: Category Script: function onChange(control, oldValue, newValue, isLoading, isTemplate) { if (isLoading || newValue === '') return; // Fetch the field choices from the server var ga = new GlideAjax( 'fetchChoiceValues' ); ga.addParam( 'sysparm_name', 'fetch' ); ga.addParam( 'sysparm_tgt_fld', 'subcategory' ); ga.addParam( 'sysparm_tgt_tbl', 'incident' ); ga.addParam( 'sysparm_dpn_val', newValue ); ga.getXML( function( res ) { // Parse the server response var result = res.responseXML.getElementsByTagName( 'result' ); var choices = JSON.parse( result[0].getAttribute( 'choices' )); // Clear the existing choices g_form.clearOptions( 'subcategory' ); // Populate the new choices for ( var i = 0, cl = choices.length; i < cl; ++i ) g_form.addOption( 'subcategory', choices[i].value, choices[i].label ); // Now we can remove the email option if ( newValue === "software" ) g_form.removeOption( 'subcategory', 'email' ); }); }