How do you hide a section in a catalogue item (via catalog client script)

stevemac
Tera Guru

Geneva Patch 6. Using item designer with catalog client scripts

Have a catalog item consisting of 2 sections.   Need to hide one of the sections.   It is labelled 'Deploy and Recovery'

I have tried using the following in a catalogue client script.

g_form.setSectionDisplay("deploy_andrecovery", false);

This causes the catalog client script to not execute.   Commenting it out ensure the script executes correctly

In the interim I am hiding all the variables in the section.   The problem with this is  that it leaves the section label  (Deploy and Recovery) visible on the form.

I do not have much experience in debugging client scripts & until now how not done much work with catalog client scripts.

Appreciate if anyone can confirm that g_form.setSectionDisplay works in a catalog client script and any recommendations on how to hide a section on a catalog item

 

thanks,

Steve

1 ACCEPTED SOLUTION

Sections and containers are different. The form tabs that you see on a table (incident.change,etc) are sections. The section like partition that you see on a service catalog is either a container, variable set or a label type field. Verify what is the type of field by right clicking and opening it's definition.



You should be able to hide them using g_form.setDisplay('name',false);


View solution in original post

8 REPLIES 8

nthumma
Giga Guru

can you try like below an '_' was missing.


g_form.setSectionDisplay("deploy_and_recovery", false);



below link might be helpful


https://www.servicenowguru.com/scripting/client-scripts-scripting/showhide-form-section/



p.s : I am not exactly sure if hiding sections work in the service catalog.


Hi Nish,



I don't think naming convension of section is wrong,



setSectionDisplay


boolean setSectionDisplay(sectionName, display)


Parameters:
sectionName - name of the section to be shown or hidden. The section name is lower case with an underscore replacing the first space in the name, and with the remaining spaces being removed, for example "Section Four is Here" becomes "section_fourishere". Other non-alphanumeric characters, such as ampersand (&), are removed. Section names can be found by using the getSectionNames method.
display - set true to show, false to hide.
Returns:
Boolean - true if successful.

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Stephen,



It works. Just tested on my G instance. Please refer below blog on how to debug client-side Erros.


Using Chrome to Debug Client Side Errors


thanks



So added some alert statements into the catalog client script


It appears that the reason it is failing is there are no sections



var sections = g_form.getSections();


alert(sections.length);



sections.length is returning 0



this is on an onLoad catalog client script.



Will test with client script on a form with sections