Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

g_form.setDisplay() not working when replacing g_form.setVisible()

armanoj
Mega Sage

 

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?

4 REPLIES 4

Ehab Pilloor
Giga Sage

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

 

  1. Navigate to Service Catalog > Catalog Definitions > Maintain Items and select the Standard Laptop item.

  2. Under Related Links, go to Variable Sets and click New.

  3. Add a variable set named Test and click Submit.

  4. Select the variable set and click New under Variables.

  5. Add a variable to the variable set with the following values:

    Question: Test var.
    Name: test_var
    Type: Single Line Text.

  6. Return to the Standard Laptop item and under Related Links, go to Catalog Client Scripts and click New.

  7. 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);
    }

  8. 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.

https://www.servicenow.com/community/servicenow-ai-platform-blog/service-catalog-on-service-portal/b...

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

in normal client script it didn't work right?

@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

Tanushree Maiti
Tera Patron

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

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti