Create and assign JSMethods at runtime

Hello everybody,

I seem to be stuck with the problem indicated in the subject. I need to reassign the onAction method of a form’s button. The fact is, the method has arguments which i need to set when reassigning it to the button. The documentation refers to a method called solutionModel.newMethodWithArguments, which unfortunately seems to be non existant…do you have any alternative? Or is this not even possible?
I tried creating a new button but the method argument does not allow you to specify arguments (no pun intended) for the method. I’m completely lost…

Hi,

I think you are referring to the function wrapMethodWithArguments() in which you pass a JSMethod with the arguments. That one is only available in Servoy 6.0.x.
What version are you using ?

ROCLASI:
Hi,

I think you are referring to the function wrapMethodWithArguments() in which you pass a JSMethod with the arguments. That one is only available in Servoy 6.0.x.
What version are you using ?

Aaaaaah, now I see! The documentation is still referring to the old method’s name and I had not a clue about the new one eheh :D
I’m using version 6.0.x so I should be ok, thanks ;)

Hi,

Can you give us the URL for the incorrect documentation so it can be fixed. I tried to search for newMethodWithArguments in the wiki but it doesn’t return any results.

ROCLASI:
Hi,

Can you give us the URL for the incorrect documentation so it can be fixed. I tried to search for newMethodWithArguments in the wiki but it doesn’t return any results.

Sure, you can find it here

EDIT: just another question. I’ve managed to create and assign the new method. Now however I’m facing a new problem: when I try to display the modified form I receive the following message:

operators missing
 > java.lang.IllegalArgumentException: operators missing

However I’m calling the method with the exact same parameters as I would if defining it from the design perspective, quoting string parameters (e.g. calling onAction.getArguments() I get [false, ‘string1’, ‘string2’]). Is it correct?

Hi,

I have corrected the docs in the code, thanks.

For the arguments, try [‘false’, “‘string1’”, “‘string2’”]

Rob

rgansevles:
Hi,

I have corrected the docs in the code, thanks.

For the arguments, try [‘false’, “‘string1’”, “‘string2’”]

Rob

Mmm…thanks for the advice, but it didn’t work…according to the docs, I should quote the string parameters, so I ended up having something like (the first one should be an event)

[null, '\'string1\'', '\'string2\'']

Unfortunately I still get the exception triggered :(

Hi,

The arguments should be an array of strings that are parsed to objects when used, so the null should also be quoted:

['null', '\'string1\'', '\'string2\'']

Rob

rgansevles:
Hi,

The arguments should be an array of strings that are parsed to objects when used, so the null should also be quoted:

['null', '\'string1\'', '\'string2\'']

Rob

No luck either…I’m starting to despair :(
I’ve looked a little for the exception and it seems to be SQL related (something about validating operators). Oh, another thing I missed is that some parameters are optional. Do I have to quote them too? In that case can I use null for them also?

EDIT: tried the last option, but no luck…

Hi,

My previous comment was not correct.
Indeed, the event arg has to be skipped with null (or anything else, it is ignored anyway).

Your sample works ok with me.
This issue is not related to the args, but indeed a query problem.
The ‘operators missing’ exception is thrown by Servoy when building a query.

Can you show some exception stack from the logs?

Rob

rgansevles:
Hi,

My previous comment was not correct.
Indeed, the event arg has to be skipped with null (or anything else, it is ignored anyway).

Your sample works ok with me.
This issue is not related to the args, but indeed a query problem.
The ‘operators missing’ exception is thrown by Servoy when building a query.

Can you show some exception stack from the logs?

Rob

Thanks for your help. I’ve just discovered that this has nothing to do with the creation of the method. This was a relation related (sorry for the pun) issue. I was creating the relation without adding a relation item to it. Sorry to have bothered you :D.
Anyhow, the correct form for the arguments is the following

[null, 'string1', 'string2']