Cannot find function getWidgetFromInstance

danmorella
Kilo Contributor

I'm trying to create a new header widget for use in a new service portal and I keep getting an error about the "getWidgetFromInstance" function when I try to fetch my menu.

js_includes_sp.jsx?v=05-16-2016_1044&lp=Tue_May_24_10_45_09_PDT_2016&c=2_42:71072 Server JavaScript error Cannot find function getWidgetFromInstance in object com.glide.service_portal.widget.fencing.ScopedSPScriptable@1044129.

Here is the server side code.

data.login_page = $sp.getValue('login_page');

var menu = $sp.getValue("sp_rectangle_menu");

data.menu = $sp.getWidgetFromInstance(menu);

It is the same first three lines that are in the stock header widget, so I have no idea why it can't find the function.

7 REPLIES 7

nathanfirth
Tera Guru

Are you working in a application scope? There are several $sp methods that do not work when they are not in Global scope.


What does that "getWidgetFromInstance" method even do?   How does it know to use the menu widget to build the actual menu? Is there any documentation on this?


The getWidgetFromInstance method generates the object needed to embed a widget in another widget. So for example I have an "instance" that defines some slides for the carousel widget, I can then call getWidgetFromInstance and pass in that instance which will return an object which can be used with the <sp-widget> directive to place that carousel and slides inside the parent widget.


How does "getWidgetFromInstance" know it's a "menu widget" when all you're passing is a sys ID.   How does it know to use a specific widget to build from that ID?   Does this mean that there's logic conditions within the "getWidgetFromInstance" which determines if the pass ID is from "menus".   And if that is the case, how do you pass the menu id of the portal and tell it to use another menu widget, as it seems to automatically use the "Header Menu" widget and because of it's limitations, i.e no class, id or 'active' events/classes on menu items, I have to build my own menu system.    


[Model]


var menu_sys_id = $sp.getValue("sp_rectangle_menu");  


// load menu into page


data.menu     = $sp.getWidgetFromInstance(menu_sys_id);



[View]


<sp-widget widget="data.menu"></sp-widget>



So my question to sum up, where does it state to use the "header menu" widget and how does one change it to use a different menu widget?