Client Script to Hide a option

Sohini Kar
Tera Expert

I have a variable "Action Required" which has two options: Add and Remove.

The requirement is: When we select Add, Option "New website access for CUI secure transfer" should be visible. And when we select Remove, that option should not be visible.

 

I wrote a client script, but When I am selecting Add, the option is showing.

When I am selecting Remove, The option is not showing.

 

But again when I am selecting Add, the option is still not showing unless I refresh the page. Kindly let me know how to fix this issue. Thanks.

 

Field Name: Type of Request

Backend value: dependent_field_1

 

I wrote the below OnChange Client Script:

 

function onChange(control, oldValue, newValue, isLoading) 
{
   if (isLoading || newValue == '1') 
   {
      g_form.addOption('dependent_field_1','New website access for CUI secure transfer');
   }
 else 
 {
          g_form.removeOption('dependent_field_1','New website access for CUI secure transfer');
                  }
   } 

 

 

 

1 ACCEPTED SOLUTION

Prince Arora
Tera Sage
Tera Sage

@Sohini Kar 

 

can you try below script:

 

function onChange(control, oldValue, newValue, isLoading) 
{
if (isLoading || newValue == '') 
{
return;
}
if(newValue=="1"){
g_form.addOption('dependent_field_1','New website access for CUI secure transfer',"New website access for CUI secure transfer");
}

else 
{
g_form.removeOption('dependent_field_1','New website access for CUI secure transfer');
}

 

 

View solution in original post

7 REPLIES 7

Thank you so much. This worked.

Ankur Bawiskar
Tera Patron
Tera Patron

@Sohini Kar 

you should use choice value during remove option

try this

function onChange(control, oldValue, newValue, isLoading) 
{
	if (isLoading)
		return; 

	if(newValue == '1')
		g_form.addOption('dependent_field_1','New website access for CUI secure transfer');
	else 
		g_form.removeOption('dependent_field_1','New website access for CUI secure transfer');
} 
Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Same issue, When I am selecting Add, the option is showing.

When I am selecting Remove, The option is not showing.

 

But again when I am selecting Add, the option is not showing unless I refresh the page.