How can Servoy method be executed (and return values collected) from NG Services?
At NG Components, there are handlers for this purpose, but handlers can’t be used within NG Services?
However, as there is no UI, there is no support for handlers.
Hi, handler are indeed not supported in NG Services, but you can still execute a Servoy function from your service (an example of such service is the window.shortcut).
You can pass a function as param of your service:
Could anyone help me with the similar question please.
I have tried passing a function that is not directly attached to the form/scope as param of my service, and then call that function when the service code runs. However, that function is not executed.
Does anyone know how to execute the function that is not attached to the form/scope by calling it from the service code.
Thank you very much.
This is the code in the scope:
/**
* @properties={typeid:24,uuid:"B070D836-9850-4C8C-B695-AB8555AB4662"}
*/
function tryExecuteCallback() {
application.output('tryExecuteCallback......');
function helloWorld() {
application.output('hello world');
}
plugins.myService.testCallback(helloWorld);
}
This is the code in the service:
function testCallback(_callback) {
console.log('testCallback......');
var _paramsToReturn = {a: 'a'};
console.log(_callback);
$window.executeInlineScript(_callback.hasOwnProperty('formname') ? _callback.formname : null, _callback.script, [_paramsToReturn]);
}
jcompagner:
that will not work, it needs to be a toplevel servoy function
Not an inner function of a servoy function, we can’t call that from the outside.
So, do you mean that $window.executeInlineScript cannot execute the inner function from the from/service? but are there any ways that Servoy provided that allows NG service can execute inner function in the form/script?
$window.executeInlineScript that is running in the browser at the client can never execute inline functions that are declared and running at the server
Because it can’t access that.
$window.executeInlineScript only knows a few params which are “formname” (or scope) + “methodname”
and an inner function is not a method of the form scope on the server, so we can’t pick it up and call it.
This is true for all callbacks in servoy, http plugin, scheduler and so on
So you need a top level scope or form function that you give as a callback.