wrapMethodWithArguments and a table view

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

wrapMethodWithArguments and a table view

Postby steve1376656734 » Mon Jun 06, 2016 6:51 pm

Hi,

I am using the solution model to add a column to table view. I am assigning a method to the onAction event using the following code:
Code: Select all
var columnField = thisForm.newField(recCaseActionCategory.category_name.replace(" ", "_") + "_icon", JSField.IMAGE_MEDIA, currentX, colHeight, colWidth, colHeight);
columnField.name = recCaseActionCategory.category_name;
columnField.scrollbars = SM_SCROLLBAR.HORIZONTAL_SCROLLBAR_NEVER | SM_SCROLLBAR.VERTICAL_SCROLLBAR_NEVER;
columnField.toolTipText = recCaseActionCategory.category_name;
columnField.onAction = solutionModel.wrapMethodWithArguments(solutionModel.getGlobalMethod("myScopeName", "myMethodName"), [null, recCaseActionCategory.case_action_category_id]);

So far this has worked fine but the requirements have changed and I now need to add an additional argument to the function which is the primary key of the record that is selected when the column field is clicked. My problem is I cannot find a way to pass this as an argument. I have tried the following code:
Code: Select all
var columnField = thisForm.newField(recCaseActionCategory.category_name.replace(" ", "_") + "_icon", JSField.IMAGE_MEDIA, currentX, colHeight, colWidth, colHeight);
columnField.name = recCaseActionCategory.category_name;
columnField.scrollbars = SM_SCROLLBAR.HORIZONTAL_SCROLLBAR_NEVER | SM_SCROLLBAR.VERTICAL_SCROLLBAR_NEVER;
columnField.toolTipText = recCaseActionCategory.category_name;columnField.onAction = solutionModel.wrapMethodWithArguments(solutionModel.getGlobalMethod("myScopeName", "myMethodName"), [null, recCaseActionCategory.case_action_category_id, forms[formName].foundset.getSelectedRecord().getPKs()]);

but this just results in the error:
Stale form(s) detected, form(s) were altered by the solution model without destroying them first

Can anyone let me know how I need to specify my argument such that the called method receives the primary key of the currently selected record when the column field is clicked please?

Thanks
Steve
Steve
SAN Developer
There are 10 types of people in the world - those that understand binary and those that don't
steve1376656734
 
Posts: 330
Joined: Fri Aug 16, 2013 2:38 pm
Location: Ashford, UK

Re: wrapMethodWithArguments and a table view

Postby patrick » Tue Jun 07, 2016 9:09 am

Looks like your problem is this

forms[formName].foundset.getSelectedRecord().getPKs()

There you already touch forms.xy, so a runtime instance. Once you have a runtime instance, you can no longer modify it. Apart from that, the idea doesn't work anyway from what I understand, because you are hard coding the ID of the first best record into your method call. So a click on any row in your table will always fire the method with the same ID. You should rather deal with the ID in your scope method. There you receive a JSEvent that allows you to figure out which form it was fired from and you can then ask that form for its selected record in your scope method.
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: wrapMethodWithArguments and a table view

Postby steve1376656734 » Tue Jun 07, 2016 9:53 am

Thanks for the info Patrick - I hadn't realised that the call to getPKs() would instantiate the form.

My first thought was to use the event parameter but when I put a breakpoint in the scope method and inspect the arguments the event parameter always seems to be null and I can't figure out why.
Steve
SAN Developer
There are 10 types of people in the world - those that understand binary and those that don't
steve1376656734
 
Posts: 330
Joined: Fri Aug 16, 2013 2:38 pm
Location: Ashford, UK

Re: wrapMethodWithArguments and a table view

Postby patrick » Tue Jun 07, 2016 10:17 am

It's not the getPKs(), but it's forms.xy that creates the runtime instance. You are asking a form (forms.xy) for something, meaning that form has to be instantiated. Whenever forms. is used, you are talking to a runtime instance.
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: wrapMethodWithArguments and a table view

Postby steve1376656734 » Tue Jun 07, 2016 10:20 am

OK - thanks for clarifying.

Any idea why the event parameter is always Null though?
Steve
SAN Developer
There are 10 types of people in the world - those that understand binary and those that don't
steve1376656734
 
Posts: 330
Joined: Fri Aug 16, 2013 2:38 pm
Location: Ashford, UK

Re: wrapMethodWithArguments and a table view

Postby patrick » Tue Jun 07, 2016 10:22 am

To make this a bit easier you could also simply create a form method for the onAction that will simply call your scope method. Something like

Code: Select all
var onActionMethod = thisForm.newMethod('function onAction_category_name(event) { myScopeName.myMethodName(event, recCaseActionCategory.case_action_category_id, foundset.getSelectedRecord().getPKs()); }');
columnField.onAction = onActionMethod
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: wrapMethodWithArguments and a table view

Postby patrick » Tue Jun 07, 2016 10:31 am

The arguments need to be quoted, so solutionModel.wrapMethodWithArguments(solutionModel.getGlobalMethod("myScopeName", "myMethodName"), [null, "'" + xx + "'"]
Last edited by patrick on Tue Jun 07, 2016 10:33 am, edited 1 time in total.
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: wrapMethodWithArguments and a table view

Postby steve1376656734 » Tue Jun 07, 2016 10:33 am

Great idea - I'm relatively new to using the solutionModel in my application and it never occurred to me to create a form method on the fly.

Thanks.
Steve
SAN Developer
There are 10 types of people in the world - those that understand binary and those that don't
steve1376656734
 
Posts: 330
Joined: Fri Aug 16, 2013 2:38 pm
Location: Ashford, UK


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 24 guests

cron