Problem accessing 'params' in scripted data source [message #922797] |
Tue, 25 September 2012 10:51 |
Paul Ramsden Messages: 84 Registered: February 2011 Location: BW, Germany |
Member |
|
|
I have a data source DS1 which has the following Property Binding:
Connection Profile Name: params["__runtime"].value.toLowerCase() == 'prod' ? 'EMOS SQL Prod' : 'EMOS SQL Test'
This has worked fine so far for normal reports. I just added '__runtime' as a report parameter and it works.
I am now trying to make a script which executes a number of data sets and I get the following error message:
Wrapped org.eclipse.birt.core.exception.CoreException: Error evaluating Javascript expression. Script engine error: ReferenceError: "params" is not defined.
Script source: <inline>, line: 0, text:
params["__runtime"].value.toLowerCase() == 'prod' ? 'EMOS SQL Prod' : 'EMOS SQL Test' (dsKontingentQueries.js#29) (Element ID:1)
This is my script:
function getDataSession(dataSourceName, dataSetName) {
debug("in getDataSession");
var myconfig = reportContext.getReportRunnable().getReportEngine().getConfig();
debug("in getDataSession2");
var des = DataRequestSession.newSession(myconfig, new DataSessionContext(3));
debug("in getDataSession3");
var dsrc = reportContext.getDesignHandle().findDataSource(dataSourceName);
debug("in getDataSession4");
var dset = reportContext.getDesignHandle().findDataSet(dataSetName);
debug("in getDataSession5"); // <=== last message, next line causes error
des.defineDataSource(des.getModelAdaptor().adaptDataSource(dsrc));
debug("in getDataSession6");
des.defineDataSet(des.getModelAdaptor().adaptDataSet(dset));
debug("leaving getDataSession");
return des;
}
Do I need to do some kind of input parameter binding here? If so, how?
[Updated on: Tue, 25 September 2012 12:51] Report message to a moderator
|
|
|
Re: Problem accessing 'params' in scripted data source [message #923230 is a reply to message #922797] |
Tue, 25 September 2012 18:29 |
|
Can you try something like the following with calling the data engine?
importPackage( Packages.org.eclipse.birt.report.model.api );
importPackage(Packages.java.lang);
importPackage(Packages.java.util);
importPackage(Packages.org.eclipse.birt.data.engine.api);
importPackage(Packages.org.eclipse.birt.report.model.api);
importPackage(Packages.org.eclipse.birt.data.engine.api.querydefn);
importPackage(Packages.org.eclipse.birt.data.engine.core);
var myconfig = reportContext.getReportRunnable().getReportEngine().getConfig();
var de = DataEngine.newDataEngine( myconfig, null );
var dsrc = reportContext.getDesignHandle().findDataSource("Data Source");
var dset = reportContext.getDesignHandle().findDataSet("Data Set");
var odaDataSource = new OdaDataSourceDesign( "Test Data Source" );
odaDataSource.setExtensionID( "org.eclipse.birt.report.data.oda.jdbc" );
odaDataSource.addPublicProperty( "odaURL", dsrc.getProperty("odaURL").toString() );
odaDataSource.addPublicProperty( "odaDriverClass", dsrc.getProperty("odaDriverClass").toString());
odaDataSource.addPublicProperty( "odaUser", dsrc.getProperty("odaUser").toString() );
odaDataSource.addPublicProperty( "odaPassword", "" );
var odaDataSet = new OdaDataSetDesign( "Test Data Set" );
odaDataSet.setDataSource( odaDataSource.getName( ) );
odaDataSet.setExtensionID( "org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
odaDataSet.setQueryText( dset.getQueryText() );
de.defineDataSource( odaDataSource );
de.defineDataSet( odaDataSet );
queryDefinition = new QueryDefinition( );
queryDefinition.setDataSetName( odaDataSet.getName() );
queryDefinition.setAutoBinding(true);
var pq = de.prepare( queryDefinition );
var qr = pq.execute( null );
rowcount=0;
var ri = qr.getResultIterator( );
while ( ri.next( ) )
{
rowcount++
}
ri.close( );
qr.close( );
de.shutdown( );
Jason
|
|
|
Re: Problem accessing 'params' in scripted data source [message #923681 is a reply to message #922797] |
Wed, 26 September 2012 05:23 |
Paul Ramsden Messages: 84 Registered: February 2011 Location: BW, Germany |
Member |
|
|
Jason
I tried the code you sent and it works though I'm not sure what it tells me. The Connection Profile Name property of the data source is a script which selects the connection based on a report parameter. It seems I'm just getting the default settings for my data source and the Connection Profile is not being used at all!
How could I modify your example script to set the connection profile property and ensure that profile selection script functions?
(I'm using BIRT 3.2.7)
Paul
[Updated on: Wed, 26 September 2012 05:53] Report message to a moderator
|
|
|
|
|
|
Re: Problem accessing 'params' in scripted data source [message #929245 is a reply to message #925390] |
Mon, 01 October 2012 10:06 |
Paul Ramsden Messages: 84 Registered: February 2011 Location: BW, Germany |
Member |
|
|
I tried this (in the DataSource beforeOpen event)
var profilePath = "connectionStore.xml";
if (reportContext.getAppContext().containsKey('BIRT_VIEWER_HTTPSERVET_REQUEST')) {
if(reportContext.getHttpServletRequest() != null) {
var rp = reportContext.getHttpServletRequest().getSession().getServletContext().getRealPath("birt/connectionStore.xml");
if( rp != null ){
profilePath = rp;
}
}
}
this.setExtensionProperty("OdaConnProfileStorePath", getProfilePath());
debug(getProfilePath());
var profileName = params["__runtime"].value.toLowerCase() == 'prod' ? 'EMOS SQL Prod' : 'EMOS SQL Test';
debug(profileName);
this.setExtensionProperty("OdaConnProfileName", profileName);
but I get the following errors
Mon Oct 01 12:02:21 CEST 2012:beforeFactory
Mon Oct 01 12:02:21 CEST 2012:queryDateRange
Mon Oct 01 12:02:21 CEST 2012:in getDataSession
Mon Oct 01 12:02:21 CEST 2012:leaving getDataSession
Mon Oct 01 12:02:21 CEST 2012:before exec
Mon Oct 01 12:02:21 CEST 2012:JavaException: org.eclipse.birt.data.engine.core.DataException: Fail to execute script in function __bm_beforeOpen(). Source:
------
" + var profilePath = "connectionStore.xml";
if (reportContext.getAppContext().containsKey('BIRT_VIEWER_HTTPSERVET_REQUEST')) {
if(reportContext.getHttpServletRequest() != null) {
var rp = reportContext.getHttpServletRequest().getSession().getServletContext().getRealPath("birt/connectionStore.xml");
if( rp != null ){
profilePath = rp;
}
}
}
this.setExtensionProperty("OdaConnProfileStorePath", getProfilePath());
debug(getProfilePath());
var profileName = params["__runtime"].value.toLowerCase() == 'prod' ? 'EMOS SQL Prod' : 'EMOS SQL Test';
debug(profileName);
this.setExtensionProperty("OdaConnProfileName", profileName);
+ "
-----
A BIRT exception occurred. See next exception for more information.
Error evaluating Javascript expression. Script engine error: Wrapped org.eclipse.birt.report.data.adapter.api.AdapterException: ReportContext method [getAppContext] can only be used in runtime. (<inline>#3)
Script source: <inline>, line: 0, text:
__bm_beforeOpen()
Mon Oct 01 12:02:21 CEST 2012:after queryDateRange
Mon Oct 01 12:02:21 CEST 2012:undefined
Mon Oct 01 12:02:21 CEST 2012:undefined
Mon Oct 01 12:02:21 CEST 2012:queryDateRange
Mon Oct 01 12:02:21 CEST 2012:in getDataSession
Mon Oct 01 12:02:21 CEST 2012:leaving getDataSession
Mon Oct 01 12:02:21 CEST 2012:before exec
Mon Oct 01 12:02:21 CEST 2012:JavaException: org.eclipse.birt.data.engine.core.DataException: Fail to execute script in function __bm_beforeOpen(). Source:
------
" + var profilePath = "connectionStore.xml";
if (reportContext.getAppContext().containsKey('BIRT_VIEWER_HTTPSERVET_REQUEST')) {
if(reportContext.getHttpServletRequest() != null) {
var rp = reportContext.getHttpServletRequest().getSession().getServletContext().getRealPath("birt/connectionStore.xml");
if( rp != null ){
profilePath = rp;
}
}
}
this.setExtensionProperty("OdaConnProfileStorePath", getProfilePath());
debug(getProfilePath());
var profileName = params["__runtime"].value.toLowerCase() == 'prod' ? 'EMOS SQL Prod' : 'EMOS SQL Test';
debug(profileName);
this.setExtensionProperty("OdaConnProfileName", profileName);
+ "
-----
A BIRT exception occurred. See next exception for more information.
Error evaluating Javascript expression. Script engine error: Wrapped org.eclipse.birt.report.data.adapter.api.AdapterException: ReportContext method [getAppContext] can only be used in runtime. (<inline>#3)
Script source: <inline>, line: 0, text:
__bm_beforeOpen()
What does 'ReportContext method [getAppContext] can only be used in runtime.' actually mean and what can I do to correct it?
Thanks
Paul
[Updated on: Mon, 01 October 2012 10:07] Report message to a moderator
|
|
|
Re: Problem accessing 'params' in scripted data source [message #929651 is a reply to message #929245] |
Mon, 01 October 2012 16:30 |
|
I assume you are getting this error when calling the data source with the data engine api. This is because you have not setup the runtime env for that particular data engine call. If you can give some more detail I may be able to help you come up with another approach. Why are your calling the de api to begin with?
Jason
|
|
|
|
Re: Problem accessing 'params' in scripted data source [message #930801 is a reply to message #930355] |
Tue, 02 October 2012 16:55 |
|
Paul
You should be able to use a scripted data set combined with a Joint data set to add to the data. The point I am confused about is why you need the DE API.
Need to setup and execute Db2 and MSSQL queries to fetch all data needed. This is why I started to mess with the DE API -- What are you doing with this data.
Jason
|
|
|
Powered by
FUDForum. Page generated in 0.05498 seconds