Calculated Field Not working

Hi Guys:

Still very new to Servoy syntax. I have a stored calculated field “Transaction_Quarter”, with the following Calc:
switch( payment_create_date.getMonth() )
{
case 1:x=1;
break;
case 2:x=1;
Break;
case 3:x=1;
Break;
case 4:x=2;
Break;
case 5:x=2;
Break;
case 6:x=2;
Break;
case 7:x=3;
Break;
case 8:x=3;
Break;
case 9:x=3;
Break;
case 10:x=4;
Break;
case 11:x=4;
Break;
case 12:x=4;
Break;
default:x=1;
}
return x;

Before I put the breaks in per the example, it would always return 1. After putting the breaks in, now I get nothing.

I’d also still like to know how to get the entire database to revalue a new Stored calc. so I can subsequently search on those fields.

Thanks!
Lee Snover

First thing to note is that getMonth() is zero based. For some crazy reasons the developers of Java thought it’d be nice to have a month 0. So you have to ask for months starting from 0 to 11.

And wouldn’t this be shorter?:

var x = payment_create_date.getMonth() + 1
return Math.ceil(x/4 ) // rounds to next highest integer

But I don’t really see what is wrong in your code either. Except that I think it has to be “break” and not “Break”…

What happens if you try:

var mo = payment_create_date.getMonth() + 1
mo = parseInt(mo);

switch (mo) ...

Just curious…

patrick:
What happens if you try:

var mo = payment_create_date.getMonth() + 1

mo = parseInt(mo);

switch (mo) …




Just curious...

Patrick, I added 1 and replaced with break; and it now seems to work.

Do you know, how do I recalc all the stored calcs?

Thanks,
Lee Snover

databaseManager.recalculate(foundset)

patrick:
databaseManager.recalculate(foundset)

Is that all I have to run? Just put it in a Method and execute from a button or the menu?

Thanks,
Lee

leesnover:

patrick:
What happens if you try:

var mo = payment_create_date.getMonth() + 1

mo = parseInt(mo);

switch (mo) …




Just curious...

Patrick, I added 1 and replaced with break; and it now seems to work.

Do you know, how do I recalc all the stored calcs?

Thanks,
Lee Snover

Patrick and Crew:

I found the problem, and it is ME!

I had inadvertanly used the “=” operator in another calc that referenced this field, when I should have used “==”. This one habit may take awhile to break. I didn’t notice, because I had ten similar calcs. right next to each other, and the others I had done properly with “==”.

Thank you all for your patience in dealing with me. Sorry to put you through the wringer for something ignorant.

Regards,
Lee Snover