NG Services to execute Servoy method

Forum to discuss the new web client version of Servoy.

NG Services to execute Servoy method

Postby imre_tokai » Thu Jan 05, 2017 1:56 pm

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
https://github.com/Servoy/servoy-client/blob/master/servoy_ngclient/src/com/servoy/j2db/server/ngclient/scripting/WebServiceScriptable.java

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
Imre Tokai, Software Engineer
iTech Professionals, Inc.
User avatar
imre_tokai
 
Posts: 33
Joined: Mon Mar 26, 2012 12:18 pm

Re: NG Services to execute Servoy method

Postby paronne » Thu Jan 05, 2017 2:24 pm

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

Code: Select all
$window.executeInlineScript(myCallback.formname, myCallback.script, [msg]);


Note that you should include the $window in your factory (or run) constructor.
paronne
 
Posts: 202
Joined: Fri Nov 02, 2012 3:21 pm

Re: NG Services to execute Servoy method

Postby jcompagner » Mon Jan 09, 2017 1:09 pm

wiki is updated for the the function property type: https://wiki.servoy.com/display/DOCS/Property+Types
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: NG Services to execute Servoy method

Postby edwardwhite7 » Tue Jul 31, 2018 3:00 pm

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:
Code: Select all
/**
* @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:
Code: Select all
function testCallback(_callback) {
   console.log('testCallback......');
   var _paramsToReturn = {a: 'a'};
   console.log(_callback);
   $window.executeInlineScript(_callback.hasOwnProperty('formname') ? _callback.formname : null, _callback.script, [_paramsToReturn]);
}
edwardwhite7
 
Posts: 3
Joined: Sun Apr 16, 2017 12:54 pm

Re: NG Services to execute Servoy method

Postby jcompagner » Tue Jul 31, 2018 4:29 pm

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.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: NG Services to execute Servoy method

Postby edwardwhite7 » Wed Aug 01, 2018 9:25 am

Hi jcompagner,

Thank you for your prompt reply for my question.
jcompagner wrote: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.
edwardwhite7
 
Posts: 3
Joined: Sun Apr 16, 2017 12:54 pm

Re: NG Services to execute Servoy method

Postby jcompagner » Wed Aug 01, 2018 11:22 am

$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.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet


Return to Servoy NGClient

Who is online

Users browsing this forum: No registered users and 5 guests