Hide/Show choice options in Record Producer

Nishant26
Tera Contributor

Hi @Ankur Bawiskar ,

 

I have a requirement to hide a particular choice option of Select Box variable based on the particular record selected in Reference Variable on the Record Producer. 

 

I have written an Onchange Client Script for the implementation but now that choice option is hidden for all records selected in Reference Variable. 

 

Here is the code:

 

if (g_form.getValue('Reference Variable name') != 'sys_id of the particular record in reference variable') {
        g_form.removeOption('Select box variable name''choice option');
 }
 
Thanks!
5 REPLIES 5

Sagar Pagar
Tera Patron

Hi @Nishant26,

 

Try this updated on change catalog client scripts on referenced variable.

if (newValue != 'sys_id of the particular record in reference variable') {
        g_form.removeOption('Select box variable name', 'choice option');
 }

 


If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers.
Thanks,
Sagar Pagar

The world works with ServiceNow

Hi @Sagar Pagar ,

 

I have tried the above code, the choice option is not visible for other records except for that particular record, but now I have to refresh the form to show that choice option for that particular record of the reference variable. it is not automatically showing that choice option after selecting that particular record for which it should be visible. 

 

is there any work around for this where I don't need to refresh the form to see that choice option after selecting that particular record in the reference variable considering I am first selecting one of those records for which it should be visible?

Hi @Nishant26,

 

You need to set the Show Unique Values checkbox as true and use the below scripts. No need to refresh the form.

 

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}

	if (newValue != 'sys_id_of_record') {
		g_form.removeOption('variable_name', 'value');
	}else{
		g_form.addOption('variable_name', 'value', 'lable');
	}   
}

 

 

If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow

Hi @Nishant26,

 

Have you looked into my comments? let me know if you have any queries to solve this issue.


If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow