Calculations don't update until saveData()

Questions, tips and tricks and techniques for scripting in Servoy

Calculations don't update until saveData()

Postby maria » Wed Jul 29, 2009 8:17 am

I have two related forms, one is in another's tab. They are related but have two other linking tables between them.
The one that's in the tab has two fields with the dataproviders being calculations from related tables.
When I update the foundset of this form (load a different record in it with loadAllRecords()) the two fields with the calculations are not updated. However, they are updated when I saveData(). I need to reflect the current state of the record. Is there a way to sort of recalculate the calculations before saving the data?

I have the same situation in another two forms that use calculations.

Please, help.
Maria
maria
 
Posts: 424
Joined: Thu Apr 16, 2009 1:18 am
Location: Sydney

Re: Calculations don't update until saveData()

Postby patrick » Wed Jul 29, 2009 11:21 am

databaseManager.recalculate() can be used to force Servoy to calculate those columns. Does that work for you?
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: Calculations don't update until saveData()

Postby maria » Thu Jul 30, 2009 2:24 am

patrick wrote:databaseManager.recalculate() can be used to force Servoy to calculate those columns. Does that work for you?


Yes, it works Patrick!
Thanks a lot!

While we are still here shall I ask another question?
I've got two relations: one holds all related records in one table for a record in another table (onetable_to_anothertable); the other holds only one default related record (onetable_to_anothertable$default).
When I have no related records but create one in the default relation (onetable_to_anothertable$default.newRecord()) and then try to see the foundset for the other relation that should include the default record I can't actually see anything there, it's empty. I do onetable_to_anothertable.loadAllRecords() but it doesn't help. Can you figure out what is missing?

Cheers,
Maria
maria
 
Posts: 424
Joined: Thu Apr 16, 2009 1:18 am
Location: Sydney

Re: Calculations don't update until saveData()

Postby patrick » Thu Jul 30, 2009 9:17 am

No, that should work. How do your relations look like? What defines the second relation as pointing to the "default"?
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: Calculations don't update until saveData()

Postby maria » Fri Jul 31, 2009 2:38 am

patrick wrote:No, that should work. How do your relations look like? What defines the second relation as pointing to the "default"?


The first relation is:
one_table_PK = other_table_FK

The second relation is:
on_table_PK = other_table_FK
true = other_table_isdefault

Looks quite common..
maria
 
Posts: 424
Joined: Thu Apr 16, 2009 1:18 am
Location: Sydney

Re: Calculations don't update until saveData()

Postby jkipling » Fri Jul 31, 2009 2:55 pm

Maria, Is your second relationship defined to allow the creation of related records through the relationship? If it is, and you are still having problems, the alternative which always works is to create the related record by copying the pk of one_table into a variable, creating a new record on a form based on other table and setting it's fk to the variable. The following is example code run from the context of one_table
Code: Select all
var theID = one_table_PK;
forms.other_table_form.controller.newRecord();
forms.other_table_form.other_table_FK = one_table_PK;

Hope this helps
-Jeremy
jkipling
 
Posts: 99
Joined: Tue Nov 20, 2007 7:46 pm
Location: Natick, MA

Re: Calculations don't update until saveData()

Postby maria » Tue Aug 04, 2009 2:57 am

jkipling wrote:Maria, Is your second relationship defined to allow the creation of related records through the relationship? If it is, and you are still having problems, the alternative which always works is to create the related record by copying the pk of one_table into a variable, creating a new record on a form based on other table and setting it's fk to the variable. The following is example code run from the context of one_table
Code: Select all
var theID = one_table_PK;
forms.other_table_form.controller.newRecord();
forms.other_table_form.other_table_FK = one_table_PK;

Hope this helps
-Jeremy


Thanks, Jeremy. That's what I did.
I'm afraid that the link between the tables was too long. After all, I changed the base table of one of the forms to a closer linking table and it worked.
maria
 
Posts: 424
Joined: Thu Apr 16, 2009 1:18 am
Location: Sydney

Re: Calculations don't update until saveData()

Postby jkipling » Tue Aug 04, 2009 2:49 pm

Maria,
I'm glad you got it to work. I just realized I had an error in my code. That code might work, but it would be better to use the variable theID in the last line, rather than the primary key directly.
jkipling
 
Posts: 99
Joined: Tue Nov 20, 2007 7:46 pm
Location: Natick, MA


Return to Methods

Who is online

Users browsing this forum: No registered users and 29 guests

cron