wrapMethodWithArguments and a table view

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:

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:

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

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.

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.

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.

OK - thanks for clarifying.

Any idea why the event parameter is always Null though?

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

var onActionMethod = thisForm.newMethod('function onAction_category_name(event) { myScopeName.myMethodName(event, recCaseActionCategory.case_action_category_id, foundset.getSelectedRecord().getPKs()); }');
columnField.onAction = onActionMethod

The arguments need to be quoted, so solutionModel.wrapMethodWithArguments(solutionModel.getGlobalMethod(“myScopeName”, “myMethodName”), [null, “'” + xx + “'”]

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.