Hi all, i have a template based dashboard.
There is a function within the template. Lets say :
function testFunc(){
alert("asd");
}
I would like to call this function from the dashboard. is that possible?
thanks
Kathy
Hi all, i have a template based dashboard.
There is a function within the template. Lets say :
function testFunc(){
alert("asd");
}
I would like to call this function from the dashboard. is that possible?
thanks
Kathy
Where is this function on the template? Is it in the ready interaction? On a button?
Hello Kathy,
In order to make this function available on the dashboard that uses the template, you can simply register the function to the window object in the template's loading event like so:
window.testFunc = function(){ alert("asd"); };
Then you will be able to call that function from scripts on the main dashboard as usual, e.g.
testFunc();
If you're planning to make multiple functions available this way, I recommend packaging them into a library so that you can avoid potential name conflicts and just general crowding of the window object. To do that, your template's loading script would look something like this:
window.testLib = {
testFunc: function(){
alert("asd");
},
anotherFunc: function(anArgument){
/* some code */
}
};
Then your dashboard can access functions from your library like this:
testLib.testFunc();
testLib.anotherFunc(aValue);