calculation firing

Questions, tips and tricks and techniques for scripting in Servoy

calculation firing

Postby Hans Nieuwenhuis » Tue May 22, 2012 9:56 am

Hi,

I have two related tables ( A and B ) and I want a calculation on table A
that fires when a datefield in one of the related records in table B changes.
The relation = A -< B ( one to many )

I created a calculation on table A and in that calculation I created a line that should cause it to fire

Code: Select all
var x = relation_a_to_b.date_field
<rest of code>


But it does not seem to work.
How can I get that calculation to fire when a corresponding datefield changes ?

Regards,
Hans Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands

Re: calculation firing

Postby rgansevles » Tue May 22, 2012 10:41 am

Hans,

Calculations are not fired when the data they depend on changes, they are only flagged for recalculation so that the next read will rerun the calc.
If a calc is shown in the UI or requested in scripting, then a flagged calc will be recalculated.

When a calc is running Servoy keeps track of the data it uses so that when that data changes it will be flagged for recalculation.
In your example, the calc depends on the relation and on the date_field of the *selected* record in the related foundset relation_a_to_b.
If there are more records in that relation, they are not touched in your example, so the calc does not depend on them.

If you read the date_field of all records in the relation, then modification of one of the date_fields should flag the calc.

Rob
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1927
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL

Re: calculation firing

Postby Hans Nieuwenhuis » Tue May 22, 2012 10:53 am

Thanks !!, but I am not sure I understand this.

How should the calculation look like to be fired ?

Regards,
Hans Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands

Re: calculation firing

Postby Hans Nieuwenhuis » Tue May 22, 2012 11:09 am

Aaaah !!, now I see.

Learned something important today. Thanks !!

B.t.w. Is this in the wiki ??, cause I did not find this there.

I now included :
Code: Select all
   for (var i=1 ; i <= relation_a_to_b.getSize() ; i++){

      application.output('dat= ' + relation_a_to_b.getRecord(i).datefield)
   }


And it works.
It fires, the next time the record from table A is shown.
Regards,
Hans Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands


Return to Methods

Who is online

Users browsing this forum: No registered users and 13 guests