<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: How to remove dependent choice list options with g_form.removeOptions in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/how-to-remove-dependent-choice-list-options-with-g-form/m-p/1380283#M37209</link>
    <description>&lt;P&gt;Asset-CI Hardware Status Mapping is used to map status or substate from asset to cmdb or hardware table. OOTB there is only one which is in_use and you might not be able to delete it since it's used by system.&lt;/P&gt;
&lt;P&gt;I thought you were trying to remove pending_repair not in_use.&lt;/P&gt;</description>
    <pubDate>Tue, 14 Apr 2020 02:08:09 GMT</pubDate>
    <dc:creator>Mike Patel</dc:creator>
    <dc:date>2020-04-14T02:08:09Z</dc:date>
    <item>
      <title>How to remove dependent choice list options with g_form.removeOptions</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-remove-dependent-choice-list-options-with-g-form/m-p/1380276#M37202</link>
      <description>&lt;P&gt;Hi all,&lt;BR /&gt;&lt;BR /&gt;I've written an onLoad client script which does quite a lot of things.&amp;nbsp; One of those things is using g_form.removeOptions on a choice list when g_form.isNewRecord() evaluates to true.&lt;/P&gt;
&lt;P&gt;It's working fine to remove options from 'hardware_status' but it will not remove options from 'hardware_substatus'.&lt;BR /&gt;&lt;BR /&gt;I've disabled all UI actions and reviewed the onLoad script to see if there would be anything interfering but have come up empty.&amp;nbsp; I'm wondering if this is happening.. or rather, not happening, because the 'hardware_substatus' choices are dependent values of the 'hardware_status' choice list.&amp;nbsp; It's a simple script... I'm not nearly skilled enough to be causing trouble with code gone wrong.&lt;/P&gt;
&lt;PRE class="language-markup"&gt;&lt;CODE&gt;function onLoad() {
	
	//Performs the following actions if the record is "new"
	
	if(g_form.isNewRecord()){
		
		//Hide form sections with read-only information which is populated by integration
		
                g_form.setSectionDisplay('network_information', false);
		g_form.setSectionDisplay('operating_systeminformation', false);
		g_form.setSectionDisplay('hardware_information', false);
		
		//Hide fields which are read only

		g_form.setDisplay('u_ad_description', false);
		g_form.setDisplay('manufacturer', false);
		g_form.setDisplay('name', false);
		g_form.setDisplay('serial_number', false);
		g_form.setDisplay('chassis_type', false);
		g_form.setDisplay('sys_updated_on', false);
		g_form.setDisplay('sys_updated_by', false);
		g_form.setDisplay('support_group', false);
		g_form.setDisplay('asset', false);
		g_form.setDisplay('model_number', false);
		
		//Set default value of 'hardware_status' to "In Stock"

		g_form.setValue('hardware_status', 'in_stock');
		
		//Remove options from 'hardware_status' so only "In Stock" is available.  Since CMDB will be used to create new assets they will always be "in stock" and exist prior to being set to any other state

		g_form.removeOption('hardware_status', 'start_retirement');
		g_form.removeOption('hardware_status', 'retired');
		g_form.removeOption('hardware_status', 'in_use');
		g_form.removeOption('hardware_substatus', 'pending_repair');
		
	}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;Any help would be appreciated.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;&lt;BR /&gt;Daniel&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Apr 2020 20:57:38 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-remove-dependent-choice-list-options-with-g-form/m-p/1380276#M37202</guid>
      <dc:creator>dwilborn</dc:creator>
      <dc:date>2020-04-12T20:57:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove dependent choice list options with g_form.removeOptions</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-remove-dependent-choice-list-options-with-g-form/m-p/1380277#M37203</link>
      <description>&lt;P&gt;I am using ternary operation for such kind of thing. ( expression ? &amp;lt;if true answer&amp;gt; : &amp;lt;if false answer&amp;gt; ;&amp;nbsp; &amp;nbsp;Note the question mark and colons - ? means to evaluate previous expression and return true or false - true is after the ? and false is after the &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So for ex in your case it would be something like:&lt;/P&gt;
&lt;P&gt;_form.isNewRecord() == "true" ?&amp;nbsp; g_form.removeOption('hardware_status', 'start_retirement') :&amp;nbsp;g_form.addOption('hardware_status', 'start_retirement');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope that helps in a way &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Joro&lt;/P&gt;</description>
      <pubDate>Sun, 12 Apr 2020 22:02:33 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-remove-dependent-choice-list-options-with-g-form/m-p/1380277#M37203</guid>
      <dc:creator>Community Alums</dc:creator>
      <dc:date>2020-04-12T22:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove dependent choice list options with g_form.removeOptions</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-remove-dependent-choice-list-options-with-g-form/m-p/1380278#M37204</link>
      <description>&lt;P&gt;Hi Joro!&lt;BR /&gt;&lt;BR /&gt;Thanks for the thought.&amp;nbsp;&amp;nbsp;While it does give me some insight into writing more succinct code it does not address the issue at hand.&lt;/P&gt;
&lt;P&gt;'pending_repair' being removed if g_form.isNewRecord == true&lt;/P&gt;
&lt;P&gt;Everything else in that script works as expected, as well as additional items beyond what I copied in, it's just that one line giving me hassle.&amp;nbsp; I'm fairly convinced it's because that particular choice list is dependent on the values of the 'hardware_status' choice list.&amp;nbsp; This is confirmed by the fact that it doesn't matter which value I try to remove or which value is selected for 'hardware_state', all options remain visible in 'hardware_substatus'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Daniel&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Apr 2020 22:24:08 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-remove-dependent-choice-list-options-with-g-form/m-p/1380278#M37204</guid>
      <dc:creator>dwilborn</dc:creator>
      <dc:date>2020-04-12T22:24:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove dependent choice list options with g_form.removeOptions</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-remove-dependent-choice-list-options-with-g-form/m-p/1380279#M37205</link>
      <description>&lt;P&gt;Make sure field is hadware_substatus. OOTB field is substatus on asset table&lt;/P&gt;
&lt;P&gt;try changing field name like below&lt;/P&gt;
&lt;P&gt;g_form.removeOption('&lt;STRONG&gt;substatus&lt;/STRONG&gt;', 'pending_repair');&lt;/P&gt;</description>
      <pubDate>Mon, 13 Apr 2020 02:20:22 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-remove-dependent-choice-list-options-with-g-form/m-p/1380279#M37205</guid>
      <dc:creator>Mike Patel</dc:creator>
      <dc:date>2020-04-13T02:20:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove dependent choice list options with g_form.removeOptions</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-remove-dependent-choice-list-options-with-g-form/m-p/1380280#M37206</link>
      <description>&lt;P&gt;Thanks Mike,&lt;BR /&gt;&lt;BR /&gt;Field label is "Substatus", field name is 'hardware_substatus'.&amp;nbsp; I have tried both.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Daniel&lt;/P&gt;</description>
      <pubDate>Mon, 13 Apr 2020 14:51:30 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-remove-dependent-choice-list-options-with-g-form/m-p/1380280#M37206</guid>
      <dc:creator>dwilborn</dc:creator>
      <dc:date>2020-04-13T14:51:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove dependent choice list options with g_form.removeOptions</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-remove-dependent-choice-list-options-with-g-form/m-p/1380281#M37207</link>
      <description>&lt;P&gt;Looks like you are looking at CMDB or computer table so try checking&amp;nbsp;alm_hardware_state_mapping.list&lt;/P&gt;
&lt;P&gt;Refer to docs on how it's setup -&amp;nbsp;&lt;A href="https://docs.servicenow.com/bundle/istanbul-it-service-management/page/product/asset-management/task/t_CreateAssetandCIHardwareStatusMapping.html" rel="nofollow"&gt;https://docs.servicenow.com/bundle/istanbul-it-service-management/page/product/asset-management/task/t_CreateAssetandCIHardwareStatusMapping.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2020 01:01:34 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-remove-dependent-choice-list-options-with-g-form/m-p/1380281#M37207</guid>
      <dc:creator>Mike Patel</dc:creator>
      <dc:date>2020-04-14T01:01:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove dependent choice list options with g_form.removeOptions</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-remove-dependent-choice-list-options-with-g-form/m-p/1380282#M37208</link>
      <description>&lt;P&gt;Thanks Mike!&amp;nbsp; Very helpful as always &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;I am executing that client script on the cmdb_ci_pc_hardware table&lt;BR /&gt;&lt;BR /&gt;The hardware status and substatus fields are synched back to the appropriate asset fields and are working as expected.&amp;nbsp; Could you help me understand how those mappings may be affecting the removal of an option from a choice list?&lt;/P&gt;
&lt;P&gt;I just tested the behavior in my PDI and the option is removed as expected with a simple&lt;BR /&gt;&lt;BR /&gt;g_form.removeOption('hardware_substatus', 'in_use');&lt;/P&gt;
&lt;P&gt;different option but same concept.&amp;nbsp; Guess I just have to keep experimenting until I figure out what I have done that is conflicting with this removal.&lt;/P&gt;
&lt;P&gt;Daniel&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2020 01:59:10 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-remove-dependent-choice-list-options-with-g-form/m-p/1380282#M37208</guid>
      <dc:creator>dwilborn</dc:creator>
      <dc:date>2020-04-14T01:59:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove dependent choice list options with g_form.removeOptions</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-remove-dependent-choice-list-options-with-g-form/m-p/1380283#M37209</link>
      <description>&lt;P&gt;Asset-CI Hardware Status Mapping is used to map status or substate from asset to cmdb or hardware table. OOTB there is only one which is in_use and you might not be able to delete it since it's used by system.&lt;/P&gt;
&lt;P&gt;I thought you were trying to remove pending_repair not in_use.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2020 02:08:09 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-remove-dependent-choice-list-options-with-g-form/m-p/1380283#M37209</guid>
      <dc:creator>Mike Patel</dc:creator>
      <dc:date>2020-04-14T02:08:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove dependent choice list options with g_form.removeOptions</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-remove-dependent-choice-list-options-with-g-form/m-p/1380284#M37210</link>
      <description>&lt;P&gt;Mike,&lt;BR /&gt;&lt;BR /&gt;In my production environment I am trying to remove 'pending_repair'.&lt;BR /&gt;&lt;BR /&gt;When I tested in my PDI I was able to remove 'in_use', in spite of it being the only option.&amp;nbsp; g_form.removeOption() doesn't delete the choice it simply "hides" it from the list, at least that's my understanding.&lt;BR /&gt;&lt;BR /&gt;At this point I'm fairly certain I have something else interfering with my desired behavior.&amp;nbsp; It doesn't appear to have anything to do with this being a dependent field based on my test in the PDI.&amp;nbsp; I'm going to disable all my UI policies and comment out every statement on the client script until I find the culprit.&lt;BR /&gt;&lt;BR /&gt;Appreciate all your thoughts on this.&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2020 07:35:07 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-remove-dependent-choice-list-options-with-g-form/m-p/1380284#M37210</guid>
      <dc:creator>dwilborn</dc:creator>
      <dc:date>2020-04-14T07:35:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove dependent choice list options with g_form.removeOptions</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-remove-dependent-choice-list-options-with-g-form/m-p/1380285#M37211</link>
      <description>&lt;P&gt;It would seem the platform didn't like&lt;/P&gt;
&lt;P&gt;g_form.setValue('hardware_status', 'in_stock');&lt;/P&gt;
&lt;P&gt;in conjunction with&amp;nbsp;&lt;/P&gt;
&lt;PRE class="language-markup"&gt;&lt;CODE&gt;g_form.removeOption('hardware_status', 'start_retirement');
g_form.removeOption('hardware_status', 'retired');
g_form.removeOption('hardware_status', 'in_use');
g_form.removeOption('hardware_substatus', 'pending_repair');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I removed the setValue statement and 'pending_repair disappeared as expected.&amp;nbsp; 'in_stock' remains as the default because it's the only option left for 'hardware_status' so I didn't need the setValue statement anyhow.&amp;nbsp; But now I'm wondering if&amp;nbsp;the 'pending_repair' function&amp;nbsp;would have worked if 'in_stock' hadn't been the only value left.&lt;BR /&gt;&lt;BR /&gt;Anyway, on to the next problem &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks again for all your thoughts on this (and all my other questions) Mike!&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2020 09:50:01 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-remove-dependent-choice-list-options-with-g-form/m-p/1380285#M37211</guid>
      <dc:creator>dwilborn</dc:creator>
      <dc:date>2020-04-14T09:50:01Z</dc:date>
    </item>
  </channel>
</rss>

