How to remove dependent choice list options with g_form.removeOptions

dwilborn
Tera Contributor

Hi all,

I've written an onLoad client script which does quite a lot of things.  One of those things is using g_form.removeOptions on a choice list when g_form.isNewRecord() evaluates to true.

It's working fine to remove options from 'hardware_status' but it will not remove options from 'hardware_substatus'.

I've disabled all UI actions and reviewed the onLoad script to see if there would be anything interfering but have come up empty.  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.  It's a simple script... I'm not nearly skilled enough to be causing trouble with code gone wrong.

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');
		
	}


Any help would be appreciated.

Thanks,

Daniel 

9 REPLIES 9

Community Alums
Not applicable

I am using ternary operation for such kind of thing. ( expression ? <if true answer> : <if false answer> ;   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 🙂 

So for ex in your case it would be something like:

_form.isNewRecord() == "true" ?  g_form.removeOption('hardware_status', 'start_retirement') : g_form.addOption('hardware_status', 'start_retirement');

 

Hope that helps in a way 🙂

 

Cheers,

Joro

Hi Joro!

Thanks for the thought.  While it does give me some insight into writing more succinct code it does not address the issue at hand.

'pending_repair' being removed if g_form.isNewRecord == true

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.  I'm fairly convinced it's because that particular choice list is dependent on the values of the 'hardware_status' choice list.  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'.

 

Thanks,

Daniel

 

 

Mike Patel
Tera Sage

Make sure field is hadware_substatus. OOTB field is substatus on asset table

try changing field name like below

g_form.removeOption('substatus', 'pending_repair');

Thanks Mike,

Field label is "Substatus", field name is 'hardware_substatus'.  I have tried both.

 

Daniel