How to get g_form.setSectionDisplay() to work in Service Portal

nathanfirth
Tera Guru

We have a simple catalog item with a few sections. I also have an embedded widget that is using the g_form API to interact with the form.

If I call:

var sections = g_form.getSectionNames();
console.log(sections)

I correctly get a list of all the sections, but when I try to hide or show a section, nothing works

g_form.setSectionDisplay(sections[0], false);

I have tested this with about a dozen different sections, in multiple scopes, and in both London and Madrid, and no matter what I do, this method does not seem to work. It's is documented as working in Service Portal with some defects being fixed in Madrid, but I'm not able to get it to work at all.

When I inspect $scope, it looks like it correctly set "visible" to false, but nothing on the form updates.

Any suggestions?

1 ACCEPTED SOLUTION

ChrisBurks
Mega Sage

Hey Nathan,

 

Try just using the setDisplay method instead of the setSectionDisplay.

g_form.setDisplay(sections[0], false);

 

View solution in original post

7 REPLIES 7

@ChrisBurks  For me its not working. 

I am getting console log correctly but also not hiding my section in portal
Onload client script 
UI Type = ALL

function onLoad() {

var sections = g_form.getSectionNames();
if(g_form.getValue('category') == '08674ad11b5624dd0dd89073be54bcbf2'){
g_form.setDisplay(sections[3], true);
}
else
g_form.setDisplay(sections[3], false);

}

One difference that I notice is that it looks like your script is within an Onload client script and is executing when that script is loaded. This is fine if the script isn't loading before the section is actually loaded into the DOM.
Check to see if it works in a different type of client script like on an onChange or try wrapping it within a setTimeout

ChrisBurks
Mega Sage

If it's for an embedded widget here's a working example of hiding a section.

find_real_file.png

_____

find_real_file.png