Problem accessing 'params' in scripted data source [message #922797] |
Tue, 25 September 2012 06:51  |
Eclipse User |
|
|
|
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 08:51] by Moderator
|
|
|
|
|
|
|
|
Re: Problem accessing 'params' in scripted data source [message #929245 is a reply to message #925390] |
Mon, 01 October 2012 06:06   |
Eclipse User |
|
|
|
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 06:07] by Moderator
|
|
|
|
|
Re: Problem accessing 'params' in scripted data source [message #930801 is a reply to message #930355] |
Tue, 02 October 2012 12:55  |
Eclipse User |
|
|
|
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.33132 seconds