Aight, I give up. What'm I doin' wrong?

I have a field that I need to update in all records. My client has about 1500 records. I have about 50 test records. The method below works in mine, but not his. On his system, java eats RAM like popcorn, but never finishes the job.

I assume it has something to do with loading 200 rows at a time, but at this point, I’m just not sure. I’m betting one of the geniuses here can just look at the code, snicker, and tell me where I’m screwing up.

TIA

forms.leadsRec.controller.show();
forms.leadsRec.controller.loadAllRecords();
while ( forms.leadsRec.controller.getSelectedIndex() < forms.leadsRec.controller.getMaxRecordIndex())
{
	forms.leadsRec.controller.setSelectedIndex (forms.leadsRec.controller.getMaxRecordIndex());
}
for (i=forms.leadsRec.controller.getMaxRecordIndex();i>0 ;i--)
{
	forms.leadsRec.controller.setSelectedIndex(i);
	if ( databaseManager.hasRecords(forms.leadsRec.leads_to_media_outlet_by_name))
	{
		forms.leadsRec.k_media_outlet = forms.leadsRec.leads_to_media_outlet_by_name.pk;
	}
}

Maybe this works:

(btw what are you trying to do here?)

forms.leadsRec.controller.show(); 
forms.leadsRec.controller.loadAllRecords();

for ( i=i ; i <= forms.leadsRec.controller.getMaxRecordIndex() ; i++ ) { 
 var record = forms.leadsRec.foundset.getRecord(i);

 if ( databaseManager.hasRecords(record.leads_to_media_outlet_by_name)) {
  record.k_media_outlet = record.leads_to_media_outlet_by_name.pk; 
 } 
}

Cain:
I assume it has something to do with loading 200 rows at a time, but at this point, I’m just not sure.

You’re right… I think your method processes only the records that are in your foundset (200 unless you already loaded a bigger foundset …) Go the way IT2BE is telling you and getMaxRecordIndex will keep authomatically increaseing so you will process all your records. If for some reason you need to process the records “bottom-up” you can place a sort before the loop…

(btw what are you trying to do here?)

I have a field that should’ve been a “lookup”. The user chooses a name, and I need to capture the actual related key so that if the name changes, the link isn’t broken. I’m just trying to go back and update existing records.

The alternative you describe is, I believe, what I started with. :( It appeared to process the first 200 records and get stuck. That’s why I added the while loop, to try to ensure that all the records were loaded. I’m only working from back to front because, at the end of the while loop, I expect to be on the last record, anyway.

I’ll try what you’ve posted, anyway, though. Perhaps it’s different in some respect that I don’t immediately see.

I’m trying to get the production data loaded into my local copy, but I’m having a separate problem importing the sample data.

Nope, I can’t believe it is the same. Maybe you did a check on ‘i < controller.getMaxRecordIndex()’.

When you do that the loop stops below that last indexed record. When you do ‘i <= controller.getMaxRecordIndex()’ the loop goes on because at 200 records (or a multitude) servoy will load the next 200 records and thus ‘controller.getMaxRecordIndex()’ is now 400…

I hope I am clear enough on this with my broken english :-)

Ciao

AHA! I’ll be that was it!

Excellent explanation. I’ll give it a shot now.

That did it. Thanx much!

That also bent my mind a bit. At first, I thought you’d forgotten to setSelectedIndex. I hadn’t realized you could load a record into a variable like that. Wow!

OK, so now I find that in order to get a stored calc to update, I need to step through existing records.

First off, as I understand it, I don’t have to show the field on the form, just select that record, right?

Second, I’m trying to use the code below, and I’m getting the same sort of “endless loop” type behavior. Perhaps I’m doing the same thing wrong again here?

It’s frustrating, because with my smaller record counts, this works fine.

forms.callsRec.controller.show();
for ( i=1 ; i <= forms.callsRec.controller.getMaxRecordIndex() ; i++ )
{
   currentcontroller.setSelectedIndex(i);
}

I wouldn’t do it like you do. Instead of:

forms.callsRec.controller.show(); 
for ( i=1 ; i <= forms.callsRec.controller.getMaxRecordIndex() ; i++ ) 
{ 
 currentcontroller.setSelectedIndex(i); //why do you go to currentcontroller????
}

I would do

forms.callsRec.controller.show(); 
for ( i=1 ; i <= forms.callsRec.controller.getMaxRecordIndex() ; i++ ) 
{ 
 forms.callsRec.controller.setSelectedIndex(i); 
}

BTW you also don’t have to do a controller.show();…

OK, I just do the show so that I can see the form on screen.

Currentcontroller vs. a named form doesn’t account for why this doesn’t work, does it?

Incidentally, why would you name a form when it’s the current controller? Since Servoy doesn’t update names across methods, this just seems like one more place to have to change if the form name ever changes.

Programming styles aside, though, (and I do like your style) I don’t think this explains why this just flat out doesn’t work on my client’s data. I just ran it for over 20 minutes, with only 1300 records, and it hadn’t redrawn the screen.

I just need a stored calc to re-evaluate. This must happen to others, and frequently. Isn’t there just a simple “step through and update” routine floating around somewhere?

Cain:
OK, I just do the show so that I can see the form on screen.

Currentcontroller vs. a named form doesn’t account for why this doesn’t work, does it?

Incidentally, why would you name a form when it’s the current controller? Since Servoy doesn’t update names across methods, this just seems like one more place to have to change if the form name ever changes.

Simply because the currentcontroller points to the controller of the MAIN form. So if this is a form in a tabpanel the currentcontroller is not the controller you wish to work with…

Programming styles aside, though, (and I do like your style) I don’t think this explains why this just flat out doesn’t work on my client’s data. I just ran it for over 20 minutes, with only 1300 records, and it hadn’t redrawn the screen.

I just need a stored calc to re-evaluate. This must happen to others, and frequently. Isn’t there just a simple “step through and update” routine floating around somewhere?

Hmm, this time I don’t have an answer but maybe to try to do a controller.loadAllRecords() first…

loadAllRecords didn’t seem to help. :(

Anyone have any other ideas why this doesn’t work?

I notice this only now:

OK, so now I find that in order to get a stored calc to update, I need to step through existing records.

Why do you need to step through the records to update the stored calculation?

What other method can I use?

I have a stored calculation that I just defined. Problem is, for the 1300 existing records, this calc hasn’t been evauated. Until I ‘look’ at the records, I won’t get the right value.

Or am I completely off base here?

I have a new report that uses this stored calc field for a subsummary. As it stands now, only the value for the first record figures, and all records show under one subsummary.

As a test, I manually stepped through a day’s worth of records (about 50). For that day, and that day alone, I can get an accurate report, with subsummaries for all the different resulting values.

If this still isn’t making sense, I could send you the solution back channel. It might be easier to understand if you could see it.

Thanks so much for taking the time, Marcel.

So, if I undestand correct you have a production system. And, you created a new stored calc for one of the tables and now want to update that field?

To be honest I haven’t done that but what you try to do seems a little drastic. Won’t a controller.saveRecord() (only once) do the job?

At least I’m pretty sure there is another way you can do that!

I this doesn’t help that solution backchannel is a good idea…

Why don’t you simply walk through all your records like IT2Be suggested and do something like

for ( i=1 ; i <= forms.callsRec.controller.getMaxRecordIndex() ; i++ ) 
{
   var record = getRecord(i);
   record.k_media_outlet;
}

That should calculate everything as you specified in the calculation. There is a problem updating calcs right now (there are quite a few discussions on this going on), but this way everything should get calculated.

When you add a new stored field on an already populated table you must loop through all your records to invoke the calculation and store the value. Or still better it would be to run an sql update command directly on your db.

Thanks, Patrick! That seems to have done it.

Still not sure why some of of the other methods didn’t work, but as the mission is accomplished, and I have this handy routine to mod and use in the future, I’m ok now. :-)

So you’re happy now? That’s good news since my evaluation didn’t come to table yesterday (sorry)…