How to hide entire section in workspace

Jessica1307
Tera Expert

"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?

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@Jessica1307 

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! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

13 REPLIES 13

GlideFather
Tera Patron

ahoy @Jessica1307,

 

it might be doable by an onLoad client script, could you share a screenshot to better understand what you want to (dinamically) hide?

---
Where the rules are real, you'll find me

@GlideFather 
For example,  there are "name" and "title"  fields belong to "Service Provider Information" section, I want to show this section  at least one field display on the form. Otherwise this section should not be displayed.

screenshot please ;))

---
Where the rules are real, you'll find me

@GlideFather ,
Screenshot is below,  Service Provider Information is folded up, there is no information. Can it not be displayed?
Jessica1307_0-1780481779883.png