- 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
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);
}
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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! 🙏
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
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
@Ankur Bawiskar
Thank you for your advice!