Discussions
Categories
Choose a Product
THRUST SERVICES
CORE APPS
CE PRODUCTS
...
Quick Links
POPULAR
HELPFUL TIPS
Groups
My Links
FOR SIGNED IN MEMBERS:
Back to website
Home
Designing Analytics Reports
RESOLVED - Java Date overwriting JavaScript Date
Migrateduser
<p>We have a common page header we use on all reports that shows the run date, run time, report name, yada, yada . . . <br><br>
In a cell we have this expression:</p>
<pre class="_prettyXprint _lang-js _linenums:1">
var runDate = toISODateString(new Date());
runDate;
</pre>
<p>Which uses a function from a common js file:</p>
<pre class="_prettyXprint _lang-js _linenums:1">
function toISODateString(d) {
return d.getUTCFullYear() +
'-' + pad(d.getUTCMonth() + 1) +
'-' + pad(d.getUTCDate());
}
</pre>
<p>And this worked great on every report but one. </p>
<blockquote class="ipsBlockquote">
<p> </p>
<p>org.eclipse.birt.report.engine.api.EngineException: A BIRT exception occurred. See next exception for more information. TypeError: Cannot find function getUTCFullYear in object Fri Feb 20 13:34:25 CST 2015. </p>
<div> (default.js#20) at org.eclipse.birt.report.engine.executor.ExecutionContext.addException(ExecutionContext.java:1245) at </div>
</blockquote>
<p> </p>
<p>Took me a minute to figure it out then I noticed that in this report we are importing java.util in our onPrepare method.</p>
<pre class="_prettyXprint _lang-xml _linenums:1">
<method name="onPrepare"><![CDATA[
importPackage(Packages.java.lang);
importPackage(Packages.java.util);
(redacted code for brevity)
]]></method>
</pre>
<p>I realized that BIRT was overwriting JavaScript Date object with Java Date Object. I changed my JavaScript function to:</p>
<pre class="_prettyXprint _lang-js _linenums:1">
function toISODateString(d) {
return d.hashCode();
}
</pre>
<p>. . . in order to verify this. It returned a hash code (which JavaScript Date object does not do).<br><br>
So I guess my question is . . . is there a way to explicitly call JavaScript.Date object? I am guessing no, but since this is such a common Java and JavaScript object that maybe this has been addressed before.</p>
<p> </p>
<p> </p>
Find more posts tagged with
Comments
There are no comments yet