Client Script - g_form.addOption() and g_form.removeOption()

Community Alums
Not applicable

I want to add an option 'Files' under choice list of 'Subcategory' field. But this option should be visible to only Service Desk group when they select 'Category' as Windows. Since there is a dependency, I am not able to get the value 'Flies' in 'Subcategory' using g_form.addOption() method.

If I am creating 'Files' under choices of 'Subcategory' making 'Windows' as dependent value then it will be visible to all. But my requirement is, it should be visible to only Service Desk group members. Even I am not able to remove that option using g_form.removeOption() method.

Any suggestions?

22 REPLIES 22

The dependent value should not matter.  Can you confirm the value of the subcategory you have in your code is correct.  Also since if it truly has a / in it you may want to use double quotes instead of single quotes.

Community Alums
Not applicable

Yes, the value is correct. I did check on that couple of times and I don't think using single or double quotes matters in this.

Let me inform you one more thing. If I am using g_form.removeOption('priority',1) is working fine. Because it does not have any dependent value. But same thing is not working for subcategory.

 

Try this then.  Remove the depending value from the subcategory and then create an onload client script to remove the subcategory unless the category is windows and the user is a member of the group that is allowed to select it.

 

Assuming you have written onchange on category field, try this code.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
  g_form.addInfoMessage("Scratchpad value is "+g_scratchpad.grp+"--cat value is "+newValue);
   if(newValue == 'Windows'){
	   g_form.addInfoMessage('inside cat loop');
	if (g_scratchpad.grp==false)
		g_form.addInfoMessage('inside scratchpad loop');
	g_form.removeOption('subcategory','File/folder restore request'); 
	  
   }
} 

Mark the comment as a correct answer and also helpful if it helps.

Community Alums
Not applicable

Hi Asifnoor,

Same result. Still that choice value is visible!