NG Services to execute Servoy method

Happy New Year!

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.

https://wiki.servoy.com/display/public/DOCS/Angular+services

Have tried couple of techniques documented below
https://wiki.servoy.com/pages/releaseview.action?pageId=1869552
but even for the closest one, getting NullPointerException referring to empty scope in this file around line 186

As a work around, built this through WebComponent that has empty .html, and it’s placed on form in kind of hidden mode

Advise please

Regards

PS.
similar post: already tried to put function within a model, than initialized it in Servoy, but getting error that it’s not properly recognized
http://forum.servoy.com/viewtopic.php?f=69&t=21368

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:

“myServiceAPi” : { “parameters”: [“name”: “myCallback”, “type” : “function”]}

You can then execute the funtion from your service like this

$window.executeInlineScript(myCallback.formname, myCallback.script, [msg]);

Note that you should include the $window in your factory (or run) constructor.

wiki is updated for the the function property type: https://wiki.servoy.com/display/DOCS/Property+Types

Hi all,

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]);
}

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.

Hi jcompagner,

Thank you for your prompt reply for my question.

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?

Thank you very much.

$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.