Home
Analytics
Making a data element visible/invisible
Rahul_NJ
Hi,
Can anyone tell me in BIRT designer, how to hide and unhide a data element based on another data element. Can this be done using JavaScript or should I use the expression builder? My requirement is as follows and I have written it using scripting :
src = this.getRowData().getColumnValue("SRC");
if (src.startsWith("IO")) {
//code to make another column "DEST" invisible.
}
Find more posts tagged with
Comments
mwilliams
Hi Rahul_NJ,
So, you want to check a value in a column and make another entire column disappear if it's a certain value? Or just the data element in that row from that column?
Rahul_NJ
Hi Michael,
Thanks for replying. Currently, I have two situations. The first one is that I want to hide a field in the report based on the value that comes in another field on the report. I have currently done it by using global variable. Could you please let me know if this is correct? It works though!
src = this.getRowData().getColumnValue("SRC");
if (src.startsWith("IO")) {
reportContext.setGlobalVariable("hide_dest", true);
}
And in the visibilty property for the field "DEST", I hide the element for all outputs and in the expression for that field, i give :
reportContext.getGlobalVariable("hide_dest"); - this returns true and hence the field gets hidden. Please advise if this approach is good.
And the second one is :
I want to make the fields in the report (with in the table) as "hidden", based on the data from a datafield that is not added in the report design (not a part of the report view), but is present in the dataset. Could you pls give a solution for this also? I am also trying out some experiments
mwilliams
Rahul_NJ,
First issue:
There are probably several ways to do it, so as long as it works, it's a good approach!
Second issue:
You can essentially do the same thing for this one. In the dataSet's onFetch script, you can set a global variable if the column you're talking about has a certain value and use that variable in the visibility expression.
Rahul_NJ
Hi Michael,
Thanks again for your help! I have found out how to get the value in the dataset and set the global variable
Thanks alot once again.
Thanks,
Rahul Sudhakaran
mwilliams
Rahul,
Is the value in the same dataSet you're using in your table? If so, you should be able to access that value in the table just like you did with the other one because it's still bound to the table regardless of if you display it.
If it's a different dataSet, you can access the row info in the script of the dataSet with 'row["column_name"]'.
Rahul_NJ
Hi Michael,
I couldnt do it in the dataset level. Hence, I added that field in the report and made it invisible. And then I accessed it the same way i did before.
Thanks,
Rahul Sudhakaran
mwilliams
Rahul,
I don't think you need to add it to the report to use the value as long as that column is bound to the table. Adding it an hiding it works too though. Glad you got it working. Let us know if you have any other questions.
Rahul_NJ
Hi Michael,
I am experiencing a problem with my script in the report which was working earlier.
The following script is added onCreate event on the data(BSOURCE) :
bsource = this.getRowData().getColumnValue("BSOURCE");
reportContext.setGlobalVariable("hide_buyTA",false);
if (bsource.startsWith("IO")) {
reportContext.setGlobalVariable("hide_buyTA",true);
}
And Im getting the following exception when i preview the report :
The following items have errors:
ReportDesign (id = 1):
- There are errors evaluating script "bsource = this.getRowData().getColumnValue("BSOURCE");
reportContext.setGlobalVariable("hide_buyTA",false);
if (bsource.startsWith("IO")) {
reportContext.setGlobalVariable("hide_buyTA",true);
}":{1}.
Error.ScriptEvaluationError ( 2 time(s) )
detail : org.eclipse.birt.report.engine.api.EngineException: There are errors evaluating script "bsource = this.getRowData().getColumnValue("BSOURCE");reportContext.setGlobalVariable("hide_buyTA",false);if (bsource.startsWith("IO")) { reportContext.setGlobalVariable("hide_buyTA",true);}":{1}. at org.eclipse.birt.report.engine.executor.ExecutionContext.evaluate(ExecutionContext.java:584) at org.eclipse.birt.report.engine.executor.ExecutionContext.evaluate(ExecutionContext.java:557) at org.eclipse.birt.report.engine.script.internal.ScriptExecutor.handleJSInternal(ScriptExecutor.java:61) at org.eclipse.birt.report.engine.script.internal.ScriptExecutor.handleJS(ScriptExecutor.java:45) at org.eclipse.birt.report.engine.script.internal.DataItemScriptExecutor.handleOnCreate(DataItemScriptExecutor.java:54) at org.eclipse.birt.report.engine.script.internal.OnCreateScriptVisitor.visitDataItem(OnCreateScriptVisitor.java:95) at org.eclipse.birt.report.engine.ir.DataItemDesign.accept(DataItemDesign.java:72) at org.eclipse.birt.report.engine.script.internal.OnCreateScriptVisitor.onCreate(OnCreateScriptVisitor.java:72) at org.eclipse.birt.report.engine.executor.ReportItemExecutor.handleOnCreate(ReportItemExecutor.java:788) at org.eclipse.birt.report.engine.executor.DataItemExecutor.execute(DataItemExecutor.java:130) at org.eclipse.birt.report.engine.internal.executor.dup.SuppressDuplicateItemExecutor.execute(SuppressDuplicateItemExecutor.java:42) at org.eclipse.birt.report.engine.internal.executor.wrap.WrappedReportItemExecutor.execute(WrappedReportItemExecutor.java:45) at org.eclipse.birt.report.engine.internal.executor.l18n.LocalizedReportItemExecutor.execute(LocalizedReportItemExecutor.java:33) at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:63) at org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:24) at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:138) at org.eclipse.birt.report.engine.layout.html.HTMLInlineStackingLM.resumeLayout(HTMLInlineStackingLM.java:107) at org.eclipse.birt.report.engine.layout.html.HTMLInlineStackingLM.layoutNodes(HTMLInlineStackingLM.java:155) at org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:24) at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:138) 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:24) at org.eclipse.birt.report.engine.layout.html.HTMLTableBandLM.layoutChildren(HTMLTableBandLM.java:65) at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:138) 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:24) at org.eclipse.birt.report.engine.layout.html.HTMLGroupLM.layoutChildren(HTMLGroupLM.java:67) at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:138) 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:24) at org.eclipse.birt.report.engine.layout.html.HTMLGroupLM.layoutChildren(HTMLGroupLM.java:67) at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:138) 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:24) 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:138) 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:85) at org.eclipse.birt.report.engine.layout.html.HTMLReportLayoutEngine.layout(HTMLReportLayoutEngine.java:106) at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:140) at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.run(RunAndRenderTask.java:68) at org.eclipse.birt.report.service.ReportEngineService.runAndRenderReport(Unknown Source) at org.eclipse.birt.report.service.ReportEngineService.runAndRenderReport(Unknown Source) at org.eclipse.birt.report.service.BirtViewerReportService.runAndRenderReport(Unknown Source) at org.eclipse.birt.report.service.actionhandler.BirtGetPageAllActionHandler.__execute(Unknown Source) at org.eclipse.birt.report.service.actionhandler.AbstractBaseActionHandler.execute(Unknown Source) at org.eclipse.birt.report.soapengine.processor.AbstractBaseDocumentProcessor.__executeAction(Unknown Source) at org.eclipse.birt.report.soapengine.processor.AbstractBaseComponentProcessor.executeAction(Unknown Source) at org.eclipse.birt.report.soapengine.processor.BirtDocumentProcessor.handleGetPageAll(Unknown Source) at sun.reflect.GeneratedMethodAccessor92.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.eclipse.birt.report.soapengine.processor.AbstractBaseComponentProcessor.process(Unknown Source) at org.eclipse.birt.report.soapengine.endpoint.BirtSoapBindingImpl.getUpdatedObjects(Unknown Source) at sun.reflect.GeneratedMethodAccessor91.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397) at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186) at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323) at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32) at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118) at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83) at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:453) at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281) at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699) at org.eclipse.birt.report.servlet.BirtSoapMessageDispatcherServlet.doPost(Unknown Source) at javax.servlet.http.HttpServlet.service(HttpServlet.java:760) at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193) at org.eclipse.birt.report.filter.ViewerFilter.doFilter(Unknown Source) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641) at org.eclipse.tomcat.internal.EclipseErrorReportValve.invoke(EclipseErrorReportValve.java:153) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardEngineValve.invoke
Thanks,
Rahul Sudhakaran
mwilliams
Rahul,
Is that the entire error?
Rahul_NJ
No sorry got cut...
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641) at org.eclipse.tomcat.internal.EclipseErrorReportValve.invoke(EclipseErrorReportValve.java:153) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683) at java.lang.Thread.run(Unknown Source)Caused by: org.mozilla.javascript.EcmaError: TypeError: Cannot call method "startsWith" of null (<inline>#3) at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3350) at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3340) at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3356) at org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3375) at org.mozilla.javascript.ScriptRuntime.undefCallError(ScriptRuntime.java:3394) at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2026) at org.mozilla.javascript.gen.c2176._c0(<inline>:3) at org.mozilla.javascript.gen.c2176.call(<inline>) at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393) at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2834) at org.mozilla.javascript.gen.c2176.call(<inline>) at org.mozilla.javascript.gen.c2176.exec(<inline>) at org.eclipse.birt.core.script.ScriptContext.eval(ScriptContext.java:223) at org.eclipse.birt.report.engine.executor.ExecutionContext.evaluate(ExecutionContext.java:578) ... 103 more
mwilliams
Rahul,
Here's what it says the error is caused by:
Caused by: org.mozilla.javascript.EcmaError: TypeError: Cannot call method "startsWith" of null
Is this column "null" at times? You could try putting an if statement around your current if statement checking bsource for null.
Rahul_NJ
Yep.. Everything works fine... Thanks Michael.. I didnt see that error showing null values.... Thanks alot once again. My report is done
Yippe ...
I owe you a treat
mwilliams
No problem. Glad I could help.