Announcing the Global SNUG Board of Directors. Learn more here
‎06-01-2019 03:50 PM
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?
Solved! Go to Solution.
‎06-01-2019 07:37 PM
Hey Nathan,
Try just using the setDisplay method instead of the setSectionDisplay.
g_form.setDisplay(sections[0], false);
‎06-01-2019 05:38 PM
I bet, you must have tried the below:
var sections = g_form.getSections(); //returns an array of html elements
g_form.setSectionDisplay(section[0], false); //In theory, setSectionDisplay expects a string as section name
This was from one of their examples on the API learning site...
‎06-01-2019 07:37 PM
Hey Nathan,
Try just using the setDisplay method instead of the setSectionDisplay.
g_form.setDisplay(sections[0], false);
‎06-03-2019 12:03 PM
Thanks Chris!
Using setDisplay does work.
This also helped me find another issue... g_form.getSectionNames does not return the "name", it manipulates the question caption and returns that, which is fundamentally wrong. I'm not sure how that ever passed QA!
‎06-02-2019 08:04 AM
Could you post more full code example, which can be used to reproduce the problem? It could be in any form (xml files, code as text files or link to GitHub with the demo). It's unclear for me which sections you mean in catalog items. Which relation have caalog item and the form. In case of usage form it's unclear where and when the statement g_form.setSectionDisplay(sections[0], false) will be executed (in Client Script, in UI Policy or directly in the code of the wigdet). If you execute the code directly in widget, then it's unclear at what stage of initialization of the form the code will be executed? One can use , for example, $scope.$on("spModel.gForm.initialized", ...) to execute some code after the form is initialized. I can continue... It's better if you post some code fragments, which explains more detailed what you do and how one could reproduce and debug the problem.