DateUtils error

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

DateUtils error

Postby Harjo » Wed Jun 06, 2018 12:25 pm

Hi there,

we use the DateUtils solution inside our solution, to calculate weeknumbers,
so far so good.

But most of the time, when we open our solution, and the weeknumber is touched in on of our calculations, we get this error:

Code: Select all
jun 06, 2018 12:12:33 PM com.servoy.j2db.util.Debug error
SEVERE: error executing calc: weeknumber
java.lang.RuntimeException: Exceptie bij het uitvoeren van berekening: weeknumber van tabel quotes, fout org.mozilla.javascript.EcmaError: ReferenceError: "calendar" is not defined. (core_DirectManager/scopes/DateUtils/getWeekOfYear#14)
   at com.servoy.j2db.scripting.TableScope.getCalculationValue(TableScope.java:193)
   at com.servoy.j2db.scripting.TableScope.getCalculationValue(TableScope.java:215)
   at com.servoy.j2db.dataprocessing.FoundSet.getCalculationValue(FoundSet.java:3403)
   at com.servoy.j2db.dataprocessing.Record.getValue(Record.java:206)
   at com.servoy.j2db.dataprocessing.Record.getValue(Record.java:169)
   at com.servoy.j2db.smart.dataui.CellAdapter$5.run(CellAdapter.java:1185)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)
Caused by: org.mozilla.javascript.EcmaError: ReferenceError: "calendar" is not defined. (core_DirectManager/scopes/DateUtils/getWeekOfYear#14)


if we look this up inside the DateUtils scope, we see this:

Code: Select all
/**
* A java.util.Calendar instance used to do the math
* @private
* @properties={typeid:35,uuid:"6FEE1C0C-ECD0-4E98-A5BA-5420B77D0917",variableType:-4}
*/
var calendar = java.util.Calendar.getInstance();



/**
* @properties={typeid:24,uuid:"A92A0657-35C4-4ECC-8F5C-8A7D2C5C0CBF"}
*/
function getWeekOfYear(date) {
   calendar.setTimeInMillis(date.getTime());
   return calendar.get(java.util.Calendar.WEEK_OF_YEAR);
}


So somehow, the first time, var calendar is not initialized somehow...
How do we make sure, that this global scope is initialized before we touch a function inside a calculation?
Harjo Kompagnie
Direct ICT / Servoy Hosting / ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
User avatar
Harjo
 
Posts: 4289
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 4 guests

cron