Home
Analytics
Can i call or use Javascript file in Report design?
Mylsamy
Hi all,
I am using Birt report 2.3.2.
Can i call the javascript file to report design?
In my javascript file , i used the word wrapping concept. When i print the data in birt report, word wrap did not apply. That is why the data is displayed as long.
Help should be appreciated..
Find more posts tagged with
Comments
mwilliams
Myl,
If I'm understanding correctly. You can call a javascript file from your report. All you need to do is add the file as a resource in your property editor for your report. Click in your report somewhere where there is no element, go to the resources section of the property editor and add the file in the javascript files section.
Mylsamy
Yes , you are correct Williams,
but Javascript resource is assigned the whole report.
But i want to access the javascript method for only the responsibilities data field.
Can i call the method to this datafield? If possible means How?
Or not possible means , is there any way to solve this?
mwilliams
Myl,
Once you've included the javaScript file as a resource to your report, you should be able to just call the function or method that you have stored in the JS file on whatever you'd like. So, if you want to use it in a computed column or something to modify a certain field to a way you'd like it, you can do so.
Mylsamy
Thanks for your reply Williams,
But when i added Javascript in resource option and run or view the report means it shows the following errors, for these errors can i add any plugin or Jar files.
But already i added all plugins and jar files to my Project.
The error is :
The following items have errors:
Data (id = 460):
- Unhandled exception when executing script.
Error.UnhandledScriptError ( 16 time(s) )
detail : org.eclipse.birt.report.engine.api.EngineException: Unhandled exception when executing script.
at org.eclipse.birt.report.engine.script.internal.ScriptExecutor.addException(ScriptExecutor.java:199)
at org.eclipse.birt.report.engine.script.internal.ScriptExecutor.addException(ScriptExecutor.java:176)
at org.eclipse.birt.report.engine.script.internal.DataItemScriptExecutor.handleOnRender(DataItemScriptExecutor.java:90)
at org.eclipse.birt.report.engine.script.internal.OnRenderScriptVisitor.visitDataItem(OnRenderScriptVisitor.java:97)
at org.eclipse.birt.report.engine.ir.DataItemDesign.accept(DataItemDesign.java:67)
at org.eclipse.birt.report.engine.script.internal.OnRenderScriptVisitor.onRender(OnRenderScriptVisitor.java:74)
at org.eclipse.birt.report.engine.presentation.LocalizedContentVisitor.handleOnRender(LocalizedContentVisitor.java:1102)
at org.eclipse.birt.report.engine.presentation.LocalizedContentVisitor.visitData(LocalizedContentVisitor.java:251)
at org.eclipse.birt.report.engine.content.impl.DataContent.accept(DataContent.java:122)
at org.eclipse.birt.report.engine.presentation.LocalizedContentVisitor.localize(LocalizedContentVisitor.java:150)
at org.eclipse.birt.report.engine.internal.executor.l18n.LocalizedReportItemExecutor.execute(LocalizedReportItemExecutor.java:36)
at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.execute(HTMLAbstractLM.java:434)
at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.execute(HTMLAbstractLM.java:442)
at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.execute(HTMLAbstractLM.java:442)
at org.eclipse.birt.report.engine.layout.html.HTMLListingBandLM.intializeHeaderContent(HTMLListingBandLM.java:96)
at org.eclipse.birt.report.engine.layout.html.HTMLListingBandLM.initialize(HTMLListingBandLM.java:48)
at org.eclipse.birt.report.engine.layout.html.HTMLTableBandLM.initialize(HTMLTableBandLM.java:42)
at org.eclipse.birt.report.engine.layout.html.HTMLLayoutManagerFactory.createLayoutManager(HTMLLayoutManagerFactory.java:50)
at org.eclipse.birt.report.engine.layout.html.HTMLReportLayoutEngine.createLayoutManager(HTMLReportLayoutEngine.java:142)
at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:67)
at org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:27)
at org.eclipse.birt.report.engine.layout.html.HTMLGroupLM.layoutChildren(HTMLGroupLM.java:80)
at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:133)
at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:68)
at org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:27)
at org.eclipse.birt.report.engine.layout.html.HTMLTableLM.layoutChildren(HTMLTableLM.java:76)
at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:133)
at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:68)
at org.eclipse.birt.report.engine.layout.html.HTMLPageLM.layout(HTMLPageLM.java:90)
at org.eclipse.birt.report.engine.layout.html.HTMLReportLayoutEngine.layout(HTMLReportLayoutEngine.java:101)
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:151)
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.run(RunAndRenderTask.java:72)
at org.eclipse.birt.report.service.ReportEngineService.runAndRenderReport(ReportEngineService.java:877)
at org.eclipse.birt.report.service.BirtViewerReportService.runAndRenderReport(BirtViewerReportService.java:938)
at org.eclipse.birt.report.service.actionhandler.BirtRunAndRenderActionHandler.__execute(BirtRunAndRenderActionHandler.java:76)
at org.eclipse.birt.report.service.actionhandler.AbstractBaseActionHandler.execute(AbstractBaseActionHandler.java:90)
at org.eclipse.birt.report.presentation.aggregation.layout.EngineFragment.doService(EngineFragment.java:318)
at org.eclipse.birt.report.presentation.aggregation.AbstractBaseFragment.service(AbstractBaseFragment.java:76)
at org.eclipse.birt.report.servlet.BirtEngineServlet.__doGet(BirtEngineServlet.java:120)
at org.eclipse.birt.report.servlet.BaseReportEngineServlet.doGet(BaseReportEngineServlet.java:185)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.eclipse.birt.report.servlet.BaseReportEngineServlet.service(BaseReportEngineServlet.java:116)
at org.eclipse.equinox.http.registry.internal.ServletManager$ServletWrapper.service(ServletManager.java:180)
at org.eclipse.equinox.http.servlet.internal.ServletRegistration.handleRequest(ServletRegistration.java:90)
at org.eclipse.equinox.http.servlet.internal.ProxyServlet.processAlias(ProxyServlet.java:111)
at org.eclipse.equinox.http.servlet.internal.ProxyServlet.service(ProxyServlet.java:59)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.eclipse.equinox.http.jetty.internal.HttpServerManager$InternalHttpServiceServlet.service(HttpServerManager.java:269)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:428)
at org.mortbay.jetty.servlet.ServletHandler.dispatch(ServletHandler.java:677)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:568)
at org.mortbay.http.HttpContext.handle(HttpContext.java:1530)
at org.mortbay.http.HttpContext.handle(HttpContext.java:1482)
at org.mortbay.http.HttpServer.service(HttpServer.java:909)
at org.mortbay.http.HttpConnection.service(HttpConnection.java:820)
at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:986)
at org.mortbay.http.HttpConnection.handle(HttpConnection.java:837)
at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:245)
at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357)
at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
Caused by: org.eclipse.birt.core.exception.CoreException: There are errors evaluating script "alertTest();":
ReferenceError: "alert" is not defined. (scripts/Test.js#2).
at org.eclipse.birt.core.script.ScriptContext.eval(ScriptContext.java:307)
at org.eclipse.birt.core.script.ScriptContext.eval(ScriptContext.java:335)
at org.eclipse.birt.report.engine.executor.ExecutionContext.evaluate(ExecutionContext.java:665)
at org.eclipse.birt.report.engine.script.internal.ScriptExecutor.handleJSInternal(ScriptExecutor.java:60)
at org.eclipse.birt.report.engine.script.internal.ScriptExecutor.handleJS(ScriptExecutor.java:47)
at org.eclipse.birt.report.engine.script.internal.DataItemScriptExecutor.handleOnRender(DataItemScriptExecutor.java:82)
... 59 more
Caused by: org.mozilla.javascript.EcmaError: ReferenceError: "alert" is not defined. (scripts/Test.js#2)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3350)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3340)
at org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:3413)
at org.mozilla.javascript.ScriptRuntime.getNameFunctionAndThis(ScriptRuntime.java:1951)
at org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:95)
at org.mozilla.javascript.gen.c116._c1(scripts/Test.js:2)
at org.mozilla.javascript.gen.c116.call(scripts/Test.js)
at org.mozilla.javascript.optimizer.OptRuntime.callName0(OptRuntime.java:108)
at org.mozilla.javascript.gen.c120._c0(/report/body/table[
@id="
;367"]/group[
@id="
;415"]/header/row[
@id="
;452"]/cell[
@id="
;455"]/data[
@id="
;460"]/method[
@name="
;onRender"]:1)
at org.mozilla.javascript.gen.c120.call(/report/body/table[
@id="
;367"]/group[
@id="
;415"]/header/row[
@id="
;452"]/cell[
@id="
;455"]/data[
@id="
;460"]/method[
@name="
;onRender"])
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2834)
at org.mozilla.javascript.gen.c120.call(/report/body/table[
@id="
;367"]/group[
@id="
;415"]/header/row[
@id="
;452"]/cell[
@id="
;455"]/data[
@id="
;460"]/method[
@name="
;onRender"])
at org.mozilla.javascript.gen.c120.exec(/report/body/table[
@id="
;367"]/group[
@id="
;415"]/header/row[
@id="
;452"]/cell[
@id="
;455"]/data[
@id="
;460"]/method[
@name="
;onRender"])
at org.eclipse.birt.core.script.ScriptContext.eval(ScriptContext.java:302)
... 64 more
Please Help me to out of this problem.
mwilliams
Myl,
Is this issue happening in the designer? Or when the report is deployed? Also, what is "alert"? That is what the error is saying is causing the issue. It's saying it is not defined.
Mylsamy
Thanks for your reply Williams,
I just added the Javascript resource. The file is sample one it's like
function test() {
alert("Test");
}
And i call these method onCreate option in script mode in report.
Then when i run the report means the error is displaying as "alert" is not defined
And i remove the alert("Test"); then also it showed the same error.
mwilliams
Myl,
When you remove the code inside the function, it still says that "alert" is not defined?
Mylsamy
Yes williams,
mwilliams
Myl,
Is this in the designer? Or when you have the report deployed? If deployed, are you restarting your application server when you make the change to the file? It doesn't make sense that it'd reference something that isn't there when you delete the code. Let me know.