Hide form sections when no fields present
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2016 03:44 AM
Hi, I have created a UI policy/actions to hide certain fields under form sections when a particular category of record is selected.
Even though there aren't any fields - the form sections are still showing.
Please can you advise how these can be hidden when the UI policy removes the fields. I have no knowledge of scripting so help on this would be greatly appreciated!
Sections/tabs showing even though fields are hidden:
Form sections
Thanks in anticipation!
Emma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2016 03:55 AM
Instead of hiding all fields in a section ,you can directly hide/display entire section using below script
var sections = g_form.getSections();
g_form.setSectionDisplay(sections[i], true);
g_form.setSectionDisplay(sections[i], false);
//in place of i provide your section number like 1 or 2 etc
Thanks,
Mihir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2016 03:57 AM
Thanks for this.
What type of script would this be and how would I set the condition please?
Emma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2016 04:02 AM
You can also use getSectionNames function also for this and directly put section names also..
13.3 getSectionNames
array getSectionNames()
- Returns all section names, whether visible or not, in an array.
- Returns:
- array - the segment names.
- GlideForm (g form) - ServiceNow Wiki
Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.
Thanks,
Deepa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2016 04:14 AM
Here is an on change client script that will hiding a section when state is 2
function onChange(control, oldValue, newValue, isLoading) {
//this example was run on a form divided into sections (Change form)
// and hid a section when the "state" field was changed
var sections = g_form.getSections();
if(isLoading){
if(g_form.getValue('state')=='2')
g_form.setSectionDisplay(sections[1], false);
}
if (newValue == '2') {
g_form.setSectionDisplay(sections[1], false);
} else {
g_form.setSectionDisplay(sections[1], true);
}
}