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

Tanushree Maiti
Tera Patron

Hi @Jessica1307 

 

Add following code in onload client script of Workspace view.

 

UI Type: All or Workspace.

Type: onLoad.

Global: Uncheck this to specify a workspace view.

View: Target the specific workspace view (like Service operation workspace)

 

function onLoad() {

g_form.setSectionDisplay('Questionnaire_nformation', false);

g_form.setSectionDisplay('Service_Provider_Information', false);

}

 

 

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

Ankur Bawiskar
Tera Patron

@Jessica1307 

so there are 2 form sections with some fields in it

You want those sections to be hidden if the fields within those sections are hidden via some UI policy or client script?

if yes then I doubt this is feasible because on the fly i.e. dynamically you won't know if section has visible field or not

💡 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

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