g_form.SetDisplay or g_form.SetVisible not working

TT3
Kilo Guru

I have below code snippet for onChange event:

if (productType == "3") { 
		g_form.addInfoMessage('in product type 3');
		g_form.setVisible('new_field', true);
		g_form.setDisplay('new_field', true);
}

Event setup:

find_real_file.png

However, when product type is 3 it shows info message, but the field is not getting changed to visible/display true. Any idea why?

3 REPLIES 3

MrMuhammad
Giga Sage

Hi,

Let's start with the basics. Can you please confirm that the variable name is correct?

If you have marked variable hidden then try unchecking that and for hiding use UI policy.

Can you please check if there is any conflicting UI policy or Client script in place? 

Also, your screenshot is missing so please use insert image in the editor to attach your screenshots.

Please mark this helpful/correct, if applicable.

Regards,

Muhammad

Servicenow Community MVP (2021 -2022)
Servicenow Developer MVP (2021)

 

Regards,
Muhammad

what is productType? it should be

if(g_form.getValue('productType')==3)

also, if it is integer value dont put 3 in " "


Raghav
MVP 2023

asifnoor
Kilo Patron

Hi,

Check if there is any UI policy which is trying to hide this field.

Also check the dictionary of this field and see if it is selected as hidden field.

considering that you are getting an info message, then it means that the field is being hidden after the client script. So there could be other client scripts or UI policies which might be running after this script and making it not visible.

Mark the comment as a correct answer and helpful if this has helped to solve the problem.