Stored Calcs not Calculating

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:

  1. 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?

  1. 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)…

Servoy v3.0. Autosave is turned ON.

This is the section of code from the nethod that creates the new rec:

//create new consign record
controller.newRecord();
//set fields
consign_barcode = globals.g_barcodeEntry;
barcode_id = barcodeID;
consign_timestamp = new Date();
consign_type = 'Bag';
comp_slip = compSlip;
user_id = globals.g_UserID;
controller.saveData();

I always put the saveData line in (even if autosave is on), out of habit.

Hmm, and you are 100% sure your calc is correct (no yellow triangle in statusbar)?

What does your calc look like?

My experience in this area is this:

  1. If a field shows on a form, of course, the calc will be calculated
  2. If a field does not show, you can not be 100% sure
  3. If you use a record variable to create a record, calcs are calculated

So it’d be interesting to see what happens if you change your code to:

//create new consign record
var vNew = foundset.getRecord(foundset.newRecord());
//set fields
vNew.consign_barcode = globals.g_barcodeEntry;
vNew.barcode_id = barcodeID;
vNew.consign_timestamp = new Date();
vNew.consign_type = 'Bag';
vNew.comp_slip = compSlip;
vNew.user_id = globals.g_UserID;
controller.saveData();

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;