g_form.setDisplay() not working when replacing g_form.setVisible()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi Community,
I am trying to replace g_form.setVisible() with g_form.setDisplay() in a Client Script.
The existing code using setVisible() works as expected:
g_form.setVisible('field_name', false);However, when I replace it with:
g_form.setDisplay('field_name', false);the field is still visible on the form.
I have verified that I am using the correct syntax and the correct field name. The Client Script is executing, and setVisible() works correctly for the same field, but setDisplay() does not seem to have any effect.
Has anyone experienced this behavior?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
50m ago - last edited 45m ago
Hi @armanoj,
Is the issue on Portal?
If yes then please refer this KB:
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0610336
Description
In Service Portal, variable set is not hidden when using g_form.setDisplay(<variable set name>, false) in a Catalog Client Script.
Steps to Reproduce
Navigate to Service Catalog > Catalog Definitions > Maintain Items and select the Standard Laptop item.
Under Related Links, go to Variable Sets and click New.
Add a variable set named Test and click Submit.
Select the variable set and click New under Variables.
Add a variable to the variable set with the following values:
Question: Test var.
Name: test_var
Type: Single Line Text.Return to the Standard Laptop item and under Related Links, go to Catalog Client Scripts and click New.
Add a client script with the following values:
Name: hide test.
UI Type: Both
Type: onLoad
Script: function onLoad() {
//Type appropriate comment here, and begin script below.
g_form.setDisplay('test', false);
}Navigate to Service Portal > Order Something > Hardware > Standard Laptop.
Note that although in Service Catalog the Test variable set is hidden, it is displayed in Service Portal.
Workaround
The intent with Service Portal is to enable our customers to provide modern, easy-to-use, device agnostic experiences for their end users or requestors. We do not intend to provide full feature parity between the Platform experience and the Service Portal experience. However, we do understand that you may have built out catalog item forms that are fairly complex and do not render well in the Service Portal today. Hopefully, the updates provided in the link below will help you overcome some of those challenges.
If they do not, there is an update set within the link that adds 2 new fields to the sc_cat_item table using iFrames but has changes that mask the iFrame experience.
Before using the update set, please understand:
- This approach is not a product offering, but only provided as an option that you can use, if you choose to do so. There will be NO SUPPORT for this.
- This is intended to be a short-term option so you can continue to use the Service Catalog on the Service Portal, while you set in motion plans to transform your catalog item forms to fit the Service Portal experience.
Related Problem: PRB718745
Please Accept this response as Solution if it assisted you with your question & Mark this response as Helpful.
Kind Regards,
Ehab Pilloor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
47m ago
in normal client script it didn't work right?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
43m ago
@armanoj,
Are you testing the working in ESC or SP?
Also if fields are mandatory, first remove mandatory then hide it, otherwise fields will be visible.
Please Accept this response as Solution if it assisted you with your question & Mark this response as Helpful.
Kind Regards,
Ehab Pilloor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
45m ago - last edited 45m ago
Hi @armanoj
Is that field mandatory?
If yes, To hide a mandatory field using g_form.setDisplay(), you must explicitly set the field to not mandatory before hiding it.
Refer:
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0717854
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0718566
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
