Calculations not updated

Hello,

I just figured that calculations are not calculated when expected. I used a loop to walk through all records, but not all records were calculated. I placed the field in question on the form and looped through it, the same: not all calcs were updated. I searched for empties, it found some, updated those, I searched again, … Finally, I had everything calculated.

In the past, it was absolutely save to walk through all records. Now it seems not to be. I have placed a feature request about having a foundset.recalculate() somewher, wouldn’t that be possible. I am just not always sure what is going on, I think this could be useful.

Thanks
Patrick

what for loop are you doing?

for example this should work fine:

for(var i=1;i<=foundset.getSize();i++)
{
var record = foundset.getRecord(i);
record.caluclation1;
record.caluclation2;
}

isn’t that working?

I did not “touch” the calc fields themselves, but simply “walked” through all records using setSelectedIndex… In the past this worked fine. I don’t use getRecord() for stuff like that because my experience was that it didn’t touch calcs. But setSelectedIndex always did the job.

then the calculation wasn’t shown on screen, so it wasn’t touched.
I think that’s why it didn’t work this time

The example i gave you ist much faster and you have everything in control. Just touch the calcs once.

I even did that though:

I placed the field in question on the form and looped through it, the same: not all calcs were updated.

What about a recalculate function that does that for me. Imagine I do what you say, I will always have to remember to add a new calc to that method. I think that is pretty unstable…

To make clear what I do:

controller.loadAllRecords()
for ( var i = 1 ; i <= controller.getMaxRecordIndex() ; i++ )
{
controller.setSelectedIndex(i);
}

The field in question is visble on the form that runs this method. Out of 6869 records in total 1629 were not calculated. The calculation is simple:

var result = '';
if (guid_firma)
{
	result += guid_firma.toString().length + '.' + guid_firma + ';'
}
if (guid_person)
{
	result += guid_person.toString().length + '.' + guid_person + ';'
}
return result;

I guess this shouldn’t be that way?

just do it the way i showed in the example Then you don’t have to have the c alc on the form (because why should that be required??)

I don’t know why they aren’t calculated at the moment.
We will see if what we can add this kind of feature that so that the calculation can go calculated.

What exactly is the expected behaviour now for recalcs?

I remember that a while ago Servoy recalculated everything whenever a record was “touched”. It didn’t matter if the fields were visible or not. Then I heard complaints about too many calcs and was also able to see this behaviour myself. This has gotten a lot better now, but obviously to a point, where I am not sure anymore what gets calculated when.

It is important for us to know exactly, what happens. Right now I have no clue. It was completely new for me that I have to use something like record.field; to update a calc.

Could someone please clarify?

P.S.: I still think that something like recalculate is an important feature…

I do believe this update feature has been requested several times, and most people agree it is needed. I am hoping it will be added by the time I migrate hunrdeds of thousands of records into my solution. I am not looking forward to have to create methods for all the calculation fields throughout all my tables.

At least I myself have requested that 5 times :wink:

I do believe this update feature has been requested several times, and most people agree it is needed. I am hoping it will be added by the time I migrate hunrdeds of thousands of records into my solution. I am not looking forward to have to create methods for all the calculation fields throughout all my tables

I have also brought up the issue of calc.s not firing properly, especially after a massive import. Things seem to be a bit better now, but I found the best solution for me was to use the back-end database tool (in my case Sybase Interactive SQL) to perform lots of 'UPDATE’s on the data I imported which is MUCH faster than any Servoy loops.

I haven’t tried Johan latest ‘touching’ loop, but might try it when I want to be sure a subset of data has calculated.

massive imports should always be done by the specialized tools.

Is there any news on the problem itself?

what is the problem itself exactly?

that you want a recalculate on foundset?
The problem is that i am not really for such a method in the servoy client.. Because that one shouldn’t be called as easy in a client because it is very very heavy. Maybe in the Dataprovider Dialog of the developer a button could be there “Recalculate”

Or that the loop through the controller and the calc isn’t updated?
You should use that foundset loop for that.
I have to see an example the look why the calcs aren’t updated with the first method.

I have the same problem here: foundset.refreshCalculations - Classic Servoy - Servoy Community

I see if I can make an example today.

Maybe in the Dataprovider Dialog of the developer a button could be there “Recalculate”

That would be a great idea. As long as it sent the right commands to the back end to update all records (like a SQL UPDATE…), this would solve my issue when I import hundreds of thousands of records.

Maybe in 2.2 final…?

Thanks,
Rafi.

i changed the behaviour now that when a record is taken from the database all the stored calculations are checked (and stored if changed)
So now only one loop of the foundset is needed. No need to touch or to display it on screen.

a simple loop over the foundset will update everything

for(var i=1;i<=foundset.getSize(); i++)
{
foundset.getRecord(i)
}

that is reasonable bahviour! :D

Great!
I’ll give it a try when the next rev. comes out.
Thanks.

just wanted to point out that we had to reverse this behaviour. Many had lots of problems of solution completely coming to a halt (in the end because of forgotten calcs or calcs that are constantly changing)

now we have databasemanager.recalculate() where you can put in a record or complete foundset.
Becarefull with complete foundsets! Don’t use it all over the place!