Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Running a query in the initalize
megabri
<p>I'm trying to create, run and save output for a query in the report's initialize function. I'm basically trying to do something like this:</p>
<p> </p>
<div>this.queryText = "select permission_id from permission where permission_desc = 'NONE'";</div>
<div> </div>
<div>vars["userOption"] = dataSetRow["permission_id"];</div>
<div> </div>
<div>I'm saving it to a variable so i can use it in queries later on in the report. How do i do this?</div>
Find more posts tagged with
Comments
micajblock
<p>Will creating a regular data set then having a hidden table at the beginning of your report work? Having the table first should ensure the query gets executed first.</p>
megabri
<p>I guess i could. I just use master pages a lot and i know that master pages are executed first so it might get out of order accidentally. Is there no way to do it in the initialize?</p>
micajblock
<p>Of course there is :-) I was just trying to simplify things.</p>
<p> </p>
<p>Check out this DevShare:</p>
<p><a data-ipb='nomediaparse' href='
http://developer.actuate.com/community/forum/index.php?/files/file/810-dynamic-content-from-library/'>http://developer.actuate.com/community/forum/index.php?/files/file/810-dynamic-content-from-library/</a></p>
;
<p> </p>
<p><span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">P.S. Do NOT use initialize, use beforeFactory!</span></p>
Matthew L.
<p>It's a bit late but the attached example might simplify what you are wanting to accomplish.</p>
<p>As mblock indicated, you should query from beforeFactory rather than the initialize method to prevent unwanted behavior.</p>
<p>However this example has a few different ways to query data from almost anywhere in a report design.</p>
<p>The most beneficial to you might be the <span style="color:#008000;">green</span> example "Query an existing data set to retrieve data."</p>
<p>Hope this helps.</p>
megabri
<p>Maybe i missed it or i'm just confused.... If i have a JDBC data source set up already how do i run a query in the beforeFactory? I'm attaching the file i'm using. Basically i want to put the UserDataSet in the before factory...</p>
Matthew L.
<p>megabri,</p>
<p> </p>
<p>I've modified your report design to show how I would accomplish querying the UserDataSet from the beforeFactory method.</p>
<p>If there is more than 1 value returned from UserDataSet's SAFER_VIEW, it will be placed as a comma separated string into the userOption report variable.</p>
Sandeep Lulla
<div>Hi,</div>
<div> </div>
<div>I am trying to execute a query on the dataset as mentioned above.</div>
<div> </div>
<div>My setup is such that i set the datasource url and username and password from the BirtNormalizer's overriden normalize() method as follows :</div>
<div> </div>
<div>
<div>public void normalize(IReportRunnable report, ReportConfiguration configuration) throws BirtReportException {</div>
<div> DesignElementHandle designElementHandle = report.getDesignHandle();</div>
<div> ModuleHandle moduleHandle = designElementHandle.getModuleHandle();</div>
<div> </div>
<div> SlotHandle dataSources = moduleHandle.getDataSources();</div>
<div> List contents = dataSources.getContents();</div>
<div> for (Object obj : contents) {</div>
<div> OdaDataSourceHandle dataSourceHandle = (OdaDataSourceHandle) obj;</div>
<div> try {</div>
<div> dataSourceHandle.setPrivateDriverProperty(ODA_DRIVER_CLASS, configuration.getReportJDBCDriverClass());</div>
<div> dataSourceHandle.setPrivateDriverProperty(ODA_URL, configuration.getReportJDBCUrl());</div>
<div> dataSourceHandle.setPrivateDriverProperty(ODA_USER, configuration.getReportJDBCUser());</div>
<div> dataSourceHandle.setPrivateDriverProperty(ODA_PASSWORD, configuration.getReportJDBCPassword());</div>
<div> } catch (SemanticException e) {</div>
<div> throw new BirtReportException(e);</div>
<div> }</div>
<div> }</div>
<div> }</div>
</div>
<div> </div>
<div>Also, i need to run the query of the dataset manually so i have written script in beforeFactory method as follows :</div>
<div> </div>
<div> </div>
<div>
<div>var myconfig = reportContext.getReportRunnable().getReportEngine().getConfig();</div>
<div>var de = DataEngine.newDataEngine( myconfig, null );</div>
<div> </div>
<div>var sqlQuery = "select * from tablename";</div>
<div> </div>
<div>var dsrc = reportContext.getDesignHandle().findDataSource("Liferay");</div>
<div>var dset = reportContext.getDesignHandle().findDataSet("GCResponseTechMap");</div>
<div> </div>
<div>var odaDataSource = new OdaDataSourceDesign( "Test Data Source" );</div>
<div>odaDataSource.setExtensionID( "org.eclipse.birt.report.data.oda.jdbc" );</div>
<div>odaDataSource.addPublicProperty( "odaURL", dsrc.getProperty("odaURL").toString() );</div>
<div>odaDataSource.addPublicProperty( "odaDriverClass", dsrc.getProperty("odaDriverClass").toString());</div>
<div>odaDataSource.addPublicProperty( "odaUser", dsrc.getProperty("odaUser").toString() );</div>
<div>odaDataSource.addPublicProperty( "odaPassword", dsrc.getProperty("odaPassword").toString() );</div>
<div> </div>
<div>System.out.println("odaDriverClass : " + dsrc.getProperty("odaDriverClass").toString());</div>
<div>System.out.println("odaURL : " + dsrc.getProperty("odaURL").toString());</div>
<div>System.out.println("user : " + dsrc.getProperty("odaUser").toString());</div>
<div>System.out.println("password : " + dsrc.getProperty("odaPassword").toString());</div>
<div> </div>
<div>The above println statements always print the values set in the datasource design and not the ones overriden by the normalize method.</div>
<div> </div>
<div>How can i get the values set by the normalize() method?</div>
<div> </div>
<div>Thanks</div>
<div>Sandeep Lulla</div>
</div>