Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
How to use env variable in rptdesign?
Jay1238
Hello,<br />
I am trying to refer env variable but does not seem to work for me. Is this the right way?<br />
<br />
<data-sources><br />
<oda-data-source extensionID="org.eclipse.datatools.enablement.oda.xml" name="Data Source" id="7"> <br />
<property name="FILELIST"></property><br />
<property name="SCHEMAFILELIST"><strong class='bbc'>$MY_HOME</strong>/design/sample.xsd</property><br />
</oda-data-source><br />
<br />
where echo $MY_HOME<br />
/home/jay<br />
<br />
It is set on linux box.<br />
<br />
Thanks,<br />
Jay
Find more posts tagged with
Comments
kclark
I tried this a few different ways and couldn't find any easier way than this.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
importPackage(Packages.java.lang);
temp = System.getenv("HOME");
reportContext.getDesignHandle().findElement("lblPath").text = temp
</pre>
<br />
This correctly changes the value of lblPath to /home/kclark -- this should translate to what you are trying to do. Let me know if it helps.
Jay1238
Thanks kclark. I don't understand where in the my rptdesign xml file should i put this piece of code of getting the env variable. Can you assist? I can email you my rpt design. Please let me know.
Thanks,
Jay
kclark
I placed that code in my onPrepare() to grab the env variable. You could do this and set the returned value to a new report variable and reference that in your XML.
Jay1238
Hi kclark,<br />
I did the following in my beforeOpen() of my Datasource. But i am not sure how to specify that global variable in SCHEMAFILELIST<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'><data-sources>
<oda-data-source extensionID="org.eclipse.datatools.enablement.oda.xml" name="Data Source" id="7">
<method name="beforeOpen"><![CDATA[importPackage(Packages.java.lang);
temp = System.getenv("windir") + "\\" + "sample.xsd";
reportContext.setGlobalVariable("test",temp)]]></method>
<property name="FILELIST">C:\Jay\0927_11665588_RN_REPLY.xml</property>
<property name="SCHEMAFILELIST">reportContext.getGlobalVariable("test")</property>
</oda-data-source>
</data-sources></pre>
kclark
Jay -- try doing the following in your beforeOpen()<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
this.setExtensionProperty("SCHEMAFILELIST",temp);
</pre>
Jay1238
<blockquote class='ipsBlockquote' data-author="'kclark'" data-cid="110502" data-time="1350312838" data-date="15 October 2012 - 07:53 AM"><p>
Jay -- try doing the following in your beforeOpen()<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
this.setExtensionProperty("SCHEMAFILELIST",temp);
</pre></p></blockquote>
<br />
This didn't seem to work for me.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'><data-sources>
<oda-data-source extensionID="org.eclipse.datatools.enablement.oda.xml" name="Data Source" id="7">
<method name="beforeOpen"><![CDATA[importPackage(Packages.java.lang);
temp = System.getenv("windir") + "\\" + "sample.xsd";
this.setExtensionProperty("SCHEMAFILELIST",temp);]]></method>
<property name="FILELIST">C:\Jay\0927_11665588_RN_REPLY.xml</property>
</oda-data-source>
</data-sources></pre>
<br />
Here is the error<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>org.eclipse.birt.report.engine.api.EngineException: An exception occurred during processing. Please see the following message for details: Cannot open the connection for the driver: org.eclipse.datatools.enablement.oda.xml.
org.eclipse.datatools.connectivity.oda.OdaException ; java.net.MalformedURLException: unknown protocol: c at org.eclipse.birt.report.engine.executor.ExecutionContext.addException(ExecutionContext.java:1199) at
org.eclipse.birt.report.engine.executor.ExecutionContext.addException(ExecutionContext.java:1178) at org.eclipse.birt.report.engine.executor.QueryItemExecutor</pre>
kclark
I was looking at<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
temp = System.getenv("windir") + "\\" + "sample.xsd";
</pre>
<br />
your env variable is "windir" and I noticed the \\ -- is this a network folder your trying to access via samba? If so try using<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
temp = System.getenv("windir") + "\\\\" + "sample.xsd";
</pre>
<br />
For ever \ there also needs to be a leading \ for the escape.<br />
<br />
If it's a local folder than it needs to be<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
temp = System.getenv("windir") + "/" + "sample.xsd";
</pre>
Jay1238
Thanks kclark for your time and help. It's working now.
Jay
kclark
No problem! Was it a network folder or local?
Jay1238
Network folder.