Help with WebClientUtils

I am trying to return a clientside value to a callback method using the WebClientUtils plugin.

Using the sample code I can trigger the callback method but have not found a way to pass a value back to it. Using this code…

var jsToExecute = "var sum = 1 + 2";
plugins.WebClientUtils.executeClientSideJS(jsToExecute, globals.callBackMethod(), ['sum'])

… the callBackMethod triggers fine but I can’t retrieve the value in ‘sum’ as an argument passed into the callback method :-(. Can anyone tell me where I am going wrong? Or does this not work in 3.5?

Servoy Developer
Version 3.5.10-build 524
Java version 1.5.0_20-141 (Mac OS X)

Hi David,

I have no experience with this plugin but I think you are using the wrong syntax to pass the method.
When you pass the method with parenthesis at the end you are in fact triggering it right there and then instead of passing the method object.
So try the following code:

var jsToExecute = "var sum = 1 + 2";
plugins.WebClientUtils.executeClientSideJS(jsToExecute, globals.callBackMethod, ['sum'])

Hope this helps.

Hi Robert,

Good suggestion. Unfortunately if I take the parentheses off then nothing happens - the callback method does not trigger at all. Of course, with the parentheses there I do not know if it triggering immediately or correctly in sequence after the clientside javascript has executed!

Hi David,

And you are sure you’re don’t need to pass the method name as a String ?

That generates an error in the log:

org.mozilla.javascript.EvaluatorException: Can’t find method com.servoy.plugins.WebClientPlugin.js_executeClientSideJS(string,string,[Ljava.lang.Object;).

Incidentally I now see that if I include the parentheses (but not in a string) that also generates an error:

org.mozilla.javascript.EvaluatorException: Can’t find method com.servoy.plugins.WebClientPlugin.js_executeClientSideJS(string,undefined,[Ljava.lang.Object;).

With no parentheses and no string there is no error in the log but still the method does not execute. Must be missing something still :?

Hi David,

You are sure the method is not triggered when you pass it without the quotes and parenthesis ? Also I see you pass the sum as a string ‘sum’ and not the variable sum.

You are sure the method is not triggered when you pass it without the quotes and parenthesis ?

For testing I use a simple method to find and load a record, then set the value in a field (I was trying to use the returned value!) - the record is not changed so I assume the method isn’t executing at all.

Also I see you pass the sum as a string ‘sum’ and not the variable sum.

Seems to require that - if I try without the inverted commas i.e. ```
plugins.WebClientUtils.executeClientSideJS(jsToExecute, globals.callBackMethod, [sum])


> ReferenceError: "sum" is not defined.

Hi David,

And if you just set a hardcoded value? Just to see if the method triggers or not.
Also where do you get this plugin ? Google seems oblivious of it.
I seem to remember that Scott or Sean made this one.

Hi Robert,

If I set the method to do something that does not rely on the returned value i.e. set field to ‘Hello’, still nothing happens so I’m pretty sure it’s not triggering.

Got the plugin from a link posted in this topic: http://www.servoy.com/forum/viewtopic.php?f=34&t=13205. The link was posted by Scott and Sean indeed made the plugin.

Direct link to plugin: Google Code Archive - Long-term storage for Google Code Project Hosting.

I am looking at the example code which is exactly what you are using and I think Sean is the one that needs to answer this one.