getting an error msg about non existing element

I get mostly after Servoy Smart Client is running a couple of hours the error message: " ‘quantity’ is not defined " when I fire always the same methode.
‘quantity’ is a column name and used as dataprovider. The methode I’m executing has a codeline " var vQuantity = quantity; " (line 13). In my methodes I cannot find any error by debugging and tried a lot to fix that issue. When I restart the Smart Client the function is working well for hours.
Ideas are welcom. I attach a log file for more information.

Servoy Client
Version 3.5.7-build 520
Java version 1.5.0_16-132 (Mac OS X)
Mac OS X 10.4.11

Thomas

error.pdf (19.9 KB)

Are you sure that you have a record selected when you call the method? Looks like the foundset is empty, could that be a chance? If not, please post your code so that we can have a look.

I don’t think that issue appears of an empty foundset. Take a look on my methodes.
First this method is starting for counting amount in all related records:

if (databaseManager.hasRecords(orders_to_orders_positions__uid_order)){
	var vRec = orders_to_orders_positions__uid_order.getSize();
	for ( var i = 0 ; i < vRec ; i++ ){
		orders_to_orders_positions__uid_order.setSelectedIndex(i + 1);
		forms.orders_pos_order_edit_dialog.m_count_amount_prices();
	}
}

The method (m_count_amount_prices) where the error is dedected in line 13 :

12- var vValue = quantity;
13- if (vValue){
14- 	m_change__article_warranty_int();//counting amount or not if warranty
15- }

What do you think about my code?
Why comes the error not always at every execute of the methods?

Thank you for your help
Thomas

tgs:

if (databaseManager.hasRecords(orders_to_orders_positions__uid_order)){
var vRec = orders_to_orders_positions__uid_order.getSize();
for ( var i = 0 ; i < vRec ; i++ ){
	orders_to_orders_positions__uid_order.setSelectedIndex(i + 1);
	forms.orders_pos_order_edit_dialog.m_count_amount_prices();
}

}

Hmm, not enough info to find a solution straight ahead, I’d need to see how the forms are related to each other but that is not the correct way of looping a foundset. Your code works only for foundsets up to 200 recs, when looping foundests you should always evaluate the size INSIDE the for loop, the reason for this is that Servoy fetches only 200 recs from the database, look at the following code:

if (databaseManager.hasRecords(orders_to_orders_positions__uid_order)){
	for ( var i = 1 ; i <= orders_to_orders_positions__uid_order.getSize() ; i++ ){
           var rec = orders_to_orders_positions__uid_order.getRecord(i)
           ...
           ...
        }

This is the correct way of looping because Servoy will re-evaluate the orders_to_orders_positions__uid_order.getSize() at every iteration and when it reaches the 200th rec it will fetch another batch of 200 from the db.

Try to use this code in your method and see if things get better.

Hello Nicola,

you are completly right with the 200 rows and the loop to a bigger foundset like 200 records. Normally I take the function:

var vRec = databaseManager.getFoundSetCount(foundset);

instead of:

var vRec = orders_to_orders_positions__uid_order.getSize();

and the loop works for me also in a foundset of more than 200 rows. But I will take your code-example, because it looks more professional ;-).

Hmm, not enough info to find a solution straight ahead, I’d need to see how the forms are related to each other

Your answer gives me an idea where the issue could be. My relation of the forms should be working by two keys. Maybe sometimes one of the keyvalue is invalid or undefined. I will check this out!

Thomas

if (databaseManager.hasRecords(orders_to_orders_positions__uid_order)){
   for ( var i = 1 ; i <= orders_to_orders_positions__uid_order.getSize() ; i++ ){
           var rec = orders_to_orders_positions__uid_order.getRecord(i)
           ...
           ...
        }

This is the correct way of looping because Servoy will re-evaluate the orders_to_orders_positions__uid_order.getSize() at every iteration and when it reaches the 200th rec it will fetch another batch of 200 from the db.

Try to use this code in your method and see if things get better.

Nicola, your code - example cannot be correct, or? What’s about 'var rec = ’ ?

My code is correct, the rec variable contains the record object for the “i” iteration of the loop so you can simply do things like this:

// increase the price by 10%
rec.price = rec.price * 1.10
// double the quantity
rec.quantity = rec.quantity * 2

and so on. No need to touch the controller of the form. The major advantage in doing this is speed: Servoy doesn’t need to update the GUI for every change you apply in your methods (you could even use a foundset not bound to any GUI at all).

what’s about 'var rec = ’ ?

What do you think is wrong?
The above about moving the record into the rec variable.
That is 100% correct

Ok, now it makes sense for me, because you are using the ‘rec’ variable for the next code-steps and not for the loop, right? :idea:
Thank you for your hint to change values in a loop without controller. One more thing for a better/faster solution.
Now I will try and than reply how it works.

Best regards
Thomas

You’re welcome! Enjoy.