onShow Error: '<field name>' is not defined

Hi,

I have an onShow method on a form that thoses some calculations with a bunch of fields setting labels to the results.

This runs just fine if I just show the form. On the contrary, if the form is show through a tab panel I get an error. This only happens the first time I show the form.

What should be the strategy to deal with this issue. Is it a bug or something that must be dealt with because of deferred loading or some framework characteristic?

Servoy Developer R2 2.2 build 328
Java 1.50-b64
windows XP

Best,
Miguel

Hi Miguel,

What does the onShow method do exactly?
Can you show us the code?

My guess is your code doesn’t take into account that it can be loaded via another form and that certain things are different (like the currentcontroller object)

Hi Robert,

Sure. Here is the pearl of programming sofistication:

// last_update field always has data!
var currYear = last_update;
currYear = currYear.getFullYear();


// Set bunch of labels for columns of data and sum total column
elements.lbl_currYear.text = currYear;
elements.lbl_lastCurrY.text = currYear - 1;                      // currYear -1
elements.lbl_beforeLastCurrY.text = currYear - 2;                // currYear -2
elements.lbl_otherXYears.text = n_acum_older_y + ' older years'; // acum of all older years


// set totals for Sales; N. of Invoices
elements.lbl_totalSales.text = curr_y_sales + last_y_sales + before_last_y_sales + older_acum_sales;
elements.lbl_totalNinvoices.text = curr_y_n_inv + last_y_n_inv + before_last_y_n_inv + older_acum_n_inv;

When the form is loaded via a tabpanel the error is:

Could not perform ‘onShow’

“last_update” is not defined.

Miguel

You say this form is loaded in a tabpanel. Is this a related form?
If so then it could be that there is no foundset. So then there is no data in last_update.

Also another option is that you are using a global method instead of a form method.
When it is a global method it will assume the frontmost form. So the form form with the tabpanel on it.
In that case you need to address the elements and fields with full names.

forms.formname.elements.elementname for the elements and forms.formname.fieldname for the field.

It was a related form and there was a related foundset (1 record), I made sure there’s data in last_update.

Also the method is local to the related form.

Unfortunately, last night I made same changes when I was half a sleep and some magic happened that I can’t reproduce the issue anymore.

I’ll try to reproduce this from scratch.

Thanks for your time Robert and I’m sorry I lost the culprit.

Best,
Miguel