getting an error msg about non existing element

Questions, answers, tips and ideas on Servoy Client

getting an error msg about non existing element

Postby tgs » Mon Jan 19, 2009 8:21 pm

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
Attachments
error.pdf
(19.87 KiB) Downloaded 313 times
Thomas Schnaus
SAN Developer
yomotec GmbH
User avatar
tgs
 
Posts: 886
Joined: Wed Oct 04, 2006 12:05 pm
Location: Germany

Re: getting an error msg about non existing element

Postby ngervasi » Mon Jan 19, 2009 8:43 pm

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.
Nicola Gervasi
sintpro.com
SAN Partner
ngervasi
 
Posts: 1485
Joined: Tue Dec 21, 2004 12:47 pm
Location: Arezzo, Italy

Re: getting an error msg about non existing element

Postby tgs » Tue Jan 20, 2009 12:49 pm

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:
Code: Select all
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 :
Code: Select all
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
Thomas Schnaus
SAN Developer
yomotec GmbH
User avatar
tgs
 
Posts: 886
Joined: Wed Oct 04, 2006 12:05 pm
Location: Germany

Re: getting an error msg about non existing element

Postby ngervasi » Tue Jan 20, 2009 1:39 pm

tgs wrote:
Code: Select all
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:

Code: Select all
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 Gervasi
sintpro.com
SAN Partner
ngervasi
 
Posts: 1485
Joined: Tue Dec 21, 2004 12:47 pm
Location: Arezzo, Italy

Re: getting an error msg about non existing element

Postby tgs » Tue Jan 20, 2009 2:54 pm

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:
Code: Select all
var vRec = databaseManager.getFoundSetCount(foundset);

instead of:
Code: Select all
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
Thomas Schnaus
SAN Developer
yomotec GmbH
User avatar
tgs
 
Posts: 886
Joined: Wed Oct 04, 2006 12:05 pm
Location: Germany

Re: getting an error msg about non existing element

Postby tgs » Tue Jan 20, 2009 3:14 pm

Code: Select all
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 = ' ?
Thomas Schnaus
SAN Developer
yomotec GmbH
User avatar
tgs
 
Posts: 886
Joined: Wed Oct 04, 2006 12:05 pm
Location: Germany

Re: getting an error msg about non existing element

Postby ngervasi » Tue Jan 20, 2009 4:04 pm

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:

Code: Select all
// 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).
Nicola Gervasi
sintpro.com
SAN Partner
ngervasi
 
Posts: 1485
Joined: Tue Dec 21, 2004 12:47 pm
Location: Arezzo, Italy

Re: getting an error msg about non existing element

Postby IT2Be » Tue Jan 20, 2009 4:06 pm

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
Marcel J.G. Trapman (IT2BE)
SAN partner - Freelance Java and Servoy
Servoy Components - IT2BE Plug-ins and Beans for Servoy
ServoyForge - Open Source Components for Servoy
User avatar
IT2Be
Servoy Expert
 
Posts: 4766
Joined: Tue Oct 14, 2003 7:09 pm
Location: Germany

Re: getting an error msg about non existing element

Postby tgs » Tue Jan 20, 2009 4:37 pm

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
Thomas Schnaus
SAN Developer
yomotec GmbH
User avatar
tgs
 
Posts: 886
Joined: Wed Oct 04, 2006 12:05 pm
Location: Germany

Re: getting an error msg about non existing element

Postby ngervasi » Tue Jan 20, 2009 4:41 pm

You're welcome! Enjoy.
Nicola Gervasi
sintpro.com
SAN Partner
ngervasi
 
Posts: 1485
Joined: Tue Dec 21, 2004 12:47 pm
Location: Arezzo, Italy


Return to Servoy Client

Who is online

Users browsing this forum: No registered users and 7 guests

cron