Hide a section in the form .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
There is a section to be hidden on the form .The form should only be visible if the Channel is self service .I tried client script but it is not working .I also tried UI policy .Below is the code I tried ,Please let me know if I am missing anything.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
section name in script should be in this format -> all name converted to lower case and space with underscore
var sectionName = 'portal_form;
also ensure you compare correct value for self service
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hello @Devika ,
After setting the g_form.setSectionDisplay function to 'false' in a client script, it does not hide the form section on page load.g_form.setSectionDisplay('<section_name>', false);
There could be two causes for this:
The setSectionDisplay function not working properly is due to how the section name is used within the function.
There are mandatory fields within the section that is being hidden.
Resolution
For #1
As per the documentation on setSectionDisplay, the section name is in lowercase 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.
For #2
It is expected behavior that if there are empty mandatory fields within the section being hidden the section itself will not be hidden. The reason is that users won't be able to see which mandatory fields to fill out if the section that contains them is hidden. If all mandatory fields have values then the section will hidden.
*note - In workspace forms, there was a defect where if the section contained any mandatory field, the section would not be hidden, even if the mandatory field had a value. The was resolved in Y release to match the UI16 behavior.
If this helps you mark it as helpful and accept as solution.
Regards,
Aditya.
technical consultant
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago - last edited 3 hours ago
Hi @Devika ,
---------------------------------------------------------------------------------------------------------------------------------------------
If your sectionName = 'Portal Form' then in script you should use snake case in lower case
g_form.setSectionDisplay(portal_form, true);
You can use it either in your client script or UI Policy.
---------------------------------------------------------------------------------------------------------------------------------------------
Please mark my response helpful and accept as solution
Thanks & Regards
Mayank
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
@Devika , the reason it might not be working is because you have used the section name in regular case.
Whereas, the g_form.setSectionDisplay(sectionName, true); accepts only lower case section name. So, you should probaly add your section name as portal_form.
Also check if there are any mandatory fields within the section.
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0696583 - refer to this article for your issue.
If my response has helped you, mark it as helpful and accept as solution.
Regards,
Nayan