Method on the fly

Questions, tips and tricks and techniques for scripting in Servoy

Method on the fly

Postby DEK4 » Thu Jul 05, 2012 8:33 am

Hello!

I have a problem... i try to create a new method with newMethod() and it doesn't work..

Code: Select all
_method = globals._dynamicForm.newMethod('function _nextStep_' + globals.getUUID() + '() { application.output("Method _nextStep"); }')
_button = globals._dynamicForm.newButton('Continua >',0+_marginLeftDTL,globals._hRowDTL*_currentRowDTL,globals._wColumnLabelDTL+globals._wColumnDataDTL,globals._hRowDTL*2,_method)
_button.onAction = _method;
_button.name = "_nextStep_" + globals.getUUID()
_button.enabled = true


thanks
User avatar
DEK4
 
Posts: 111
Joined: Wed Oct 12, 2011 9:26 am

Re: Method on the fly

Postby ROCLASI » Thu Jul 05, 2012 9:35 am

Hi,

You are using a UUID in the method name. This UUID has hyphens (-) in there and those are not supported in a function name so you should strip them out.
In fact hyphens are not really supported in any object name.

Try the following code instead:
Code: Select all
_method = globals._dynamicForm.newMethod('function _nextStep_' + utils.stringReplace(globals.getUUID(), "-","") + '() { application.output("Method _nextStep"); }')
_button = globals._dynamicForm.newButton('Continua >',0+_marginLeftDTL,globals._hRowDTL*_currentRowDTL,globals._wColumnLabelDTL+globals._wColumnDataDTL,globals._hRowDTL*2,_method)
_button.onAction = _method;
_button.name = "_nextStep_" + utils.stringReplace(globals.getUUID(), "-","")
_button.enabled = true


Hope this helps.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: Method on the fly

Postby DEK4 » Thu Jul 05, 2012 10:18 am

Hi, thanks for your answer...but it doesn't work...

i try also without the getUUID but nothing...
User avatar
DEK4
 
Posts: 111
Joined: Wed Oct 12, 2011 9:26 am

Re: Method on the fly

Postby Joas » Thu Jul 05, 2012 11:41 am

Did you call controller.recreateUI() on your changed form?
Joas de Haan
Yield Software Development
Need help on your project? yieldsd.com
User avatar
Joas
Site Admin
 
Posts: 842
Joined: Mon Mar 20, 2006 4:07 pm
Location: Leusden, NL

Re: Method on the fly

Postby DEK4 » Thu Jul 05, 2012 12:34 pm

Yes but nothing......

Code: Select all
_method = globals._dynamicForm.newMethod('function aMethod(event){application.output("Hello world!");}');
_button = globals._dynamicForm.newButton('Continua >',0+_marginLeftDTL,globals._hRowDTL*_currentRowDTL,globals._wColumnLabelDTL+globals._wColumnDataDTL,globals._hRowDTL*2,_method)
_button.onAction = _method;
_button.name = "_nextStep_" + utils.stringReplace(globals.getUUID(), "-","")
_button.enabled = true
controller.recreateUI()
return false
User avatar
DEK4
 
Posts: 111
Joined: Wed Oct 12, 2011 9:26 am

Re: Method on the fly

Postby ROCLASI » Thu Jul 05, 2012 1:29 pm

Hi,

What exactly doesn't work ?
The button doesn't show up ? Or clicking the button doesn't seem to trigger the method, i.e. you don't see the application.output ?
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: Method on the fly

Postby omar » Thu Jul 05, 2012 3:15 pm

Hi,

I simplified your example and was able to reproduce your problem when the global form var did not contain a valid object. Like this it works:

Code: Select all
   if (!globals._dynamicForm) {
      globals._dynamicForm = solutionModel.getForm('frmWhatEver');
   }
   var method = globals._dynamicForm.newMethod('function myMethod(event) { plugins.dialogs.showInfoDialog("Test","Hello World");}');
   servoyDeveloper.save(globals._dynamicForm);
   var button = globals._dynamicForm.newButton('Hello World',250,250,80,20,method);
   button.name = 'myNewButton';
   currentcontroller.recreateUI();


Perhaps the assumption that globals.dynamicForm is filled is mistaken?
Intrasoft, Founder
Omar van Galen
omar@intrasoft.nl
+31-(0)6-21234586
Servoy Developer
omar
 
Posts: 377
Joined: Sat Feb 12, 2011 4:51 pm
Location: Intrasoft, The Netherlands


Return to Methods

Who is online

Users browsing this forum: No registered users and 8 guests