g_form.SetDisplay or g_form.SetVisible not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2022 09:52 AM
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:
However, when product type is 3 it shows info message, but the field is not getting changed to visible/display true. Any idea why?
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2022 10:00 AM
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)
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2022 11:35 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2022 04:05 PM
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.