I have a problem with 2 stored calculations on a table, based on a datetime field.
Basically the calcs work out the week number and month number of the datetime. Both these calcs work ok and store the result ok when I loop thru the records in Developer (on a form with both fields displayed).
However when a client creates a new record (via a method, the calc fields are not displayed on the form) with an entry in the datetime field, the stored calc fields are not populated.
I am slightly baffled. Questions I have are:
Do the calc fields have to be displayed on the form where the new record is created in order to populate them?
1a) If not, why arent my calc fields getting populated?
When using the recalculate funtion is the following viable syntax to recalc the current rec? ```
databaseManager.recalculate(foundset.getRecord(controller.getSelectedIndex()));
Which Servoy are you using?
If 3.0 do you autosave?
I can imagine that, without it, a calc is not recalculated (although this doesn’t sound like the right behaviour)…
No luck with the record variable. The calcs are still not populating on clients.
Just to make this clear, the method that contains the code to create a new method works fine when you run it in developer, under the same conditions as it would when run by a client. But when it runs on a client, the calcs are not populated.
Here is one of the calcs:
var theDate = consign_timestamp;
var day = theDate.getDate();
var month = theDate.getMonth();
var year = theDate.getFullYear();
var when = new Date(year,month,day);
var newYear = new Date(year,0,1);
var modDay = newYear.getDay();
if (modDay == 0) modDay=6; else modDay--;
var daynum = ((Date.UTC(year,when.getMonth(),when.getDate(),0,0,0) -
Date.UTC(year,0,1,0,0,0)) /1000/60/60/24) + 1;
if (modDay < 4 )
{
var weeknum = Math.floor((daynum+modDay-1)/7)+1;
}
else
{
var weeknum = Math.floor((daynum+modDay-1)/7);
if (weeknum == 0)
{
year--;
var prevNewYear = new Date(year,0,1);
var prevmodDay = prevNewYear.getDay();
if (prevmodDay == 0) prevmodDay = 6; else prevmodDay--;
if (prevmodDay < 4) weeknum = 53; else weeknum = 52;
}
}
var weeknumStr = weeknum + '';
if (weeknumStr.length <2) weeknumStr = '0' + weeknumStr;
var theYear = year;
return theYear + "-" + weeknumStr;