- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
"Questionnaire Information" and "Service Provider Information" are two sections. I want to hide them if there are no visible fields under them. Is it possible to hide them dynamically?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
try this once
add your correct section name and field names within those sections
Section name is name of section in lower case and space replaced with underscore
function toggleSection(sectionName, fields) {
var showSection = false;
for (var i = 0; i < fields.length; i++) {
if (g_form.isVisible(fields[i])) {
showSection = true;
break;
}
}
g_form.setSectionDisplay(sectionName, showSection);
}
function onLoad() {
toggleSection('questionnaire_information', ['field1', 'field2', 'field3']);
toggleSection('service_provider_information', ['field4', 'field5']);
}
💡 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 || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
oh come on @Jessica1307 I am trying to help you here in my free time...
Please attach some helpful screenshot to see what section you are referring to. the better question the better answer. I cannot help you without context or visibility. What do you say?
Where the rules are real, you'll find me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@GlideFather ,
Sorry to bother you, Let explain what I want to do. There are three fields under "Closure Information" section as below picture
There is existed script make these three fields not display on the form based some condition but the "Closure Information" section still display on the form even though this three fields are hidden on the form( refer below picture).
Now I want to hide this section when the fields belong to it are not display on the form, Do you have any ideas? Thank you in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
if your script knows all the fields are to be marked as hidden then in same script add the logic to hide the section as well
g_form.setSectionDisplay('closure_information', false);
💡 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 || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@Ankur Bawiskar ,
I need to hide many section and I don't know how many fields marked. So I can't add the logic directly to hide the section. Is there a way to get the fields under each section and then determine if there are fields displayed on the screen? If there are, then show that part; if not, hide the section.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I shared sample script below
try using this to check if field is visible or not
g_form.isVisible('field1'); // returns true or false
💡 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 || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader