Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Default Dynamic Parameter
Default Dynamic Parameter [message #635155] Mon, 25 October 2010 19:20 Go to next message
Bernie Durfee is currently offline Bernie Durfee
Messages: 6
Registered: October 2010
Junior Member
I've created a dynamic list box report parameter and would like to set the default value to be the first item in the list. Is that possible or can I only specify a static value for the default value?


Thanks...
Re: Default Dynamic Parameter [message #635164 is a reply to message #635155] Mon, 25 October 2010 19:54 Go to previous messageGo to next message
Richard A. Polunsky is currently offline Richard A. Polunsky
Messages: 199
Registered: July 2009
Location: Houston TX
Senior Member

If you're showing the listbox interactively and have an order by clause on the query, the first item in the list will be presented.

If you want to actually have that as the default value (preselected) then you will need to iterate over the dropdown values in the parameter value event script. I've seen references to that somewhere, that was added in 2.5.
Re: Default Dynamic Parameter [message #635170 is a reply to message #635164] Mon, 25 October 2010 20:25 Go to previous messageGo to next message
Bernie Durfee is currently offline Bernie Durfee
Messages: 6
Registered: October 2010
Junior Member
Yes, what I want is to have the first item in the list box preselected, since most of the time that's the option that the user will choose anyway.
Re: Default Dynamic Parameter [message #635177 is a reply to message #635155] Mon, 25 October 2010 21:00 Go to previous messageGo to next message
Richard A. Polunsky is currently offline Richard A. Polunsky
Messages: 199
Registered: July 2009
Location: Houston TX
Senior Member

Sorry, I missed that this was a listbox and not a combo box. You need to run iteratively through the values and set the one you want. I just won't have time to find where I think I did that for a week. Hopefully someone else has done this.
Re: Default Dynamic Parameter [message #635380 is a reply to message #635177] Tue, 26 October 2010 14:57 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

If you do not set a default value and are using the viewer, the first
item returned should be preselected automatically in the parameter entry
box.

Jason

On 10/25/2010 5:00 PM, Richard A. Polunsky wrote:
> Sorry, I missed that this was a listbox and not a combo box. You need
> to run iteratively through the values and set the one you want. I just
> won't have time to find where I think I did that for a week. Hopefully
> someone else has done this.
Re: Default Dynamic Parameter [message #637220 is a reply to message #635155] Thu, 04 November 2010 16:06 Go to previous messageGo to next message
Bernie Durfee is currently offline Bernie Durfee
Messages: 6
Registered: October 2010
Junior Member
It looks like I can maybe do what I want using 'getdefaultvaluelist', but I can't find any examples. The values in the combo-box come from a data set, that returns a list of academic terms...

TERM_CODE
TERM_DESC
TERM_START
TERM_END

...the terms in the list include some past and some future terms. I want the current term selected by default. So in pseudo-code I figure I should be able to...

Create array with default values

Iterate through the values in the dataset to find the term code where today's date is between the term start and end dates

Add the term code to the array so it becomes the default value

...I just don't know what's available within the context of the 'getdefaultvaluelist' call. Anyone want to get me started here?
Re: Default Dynamic Parameter [message #637258 is a reply to message #637220] Thu, 04 November 2010 17:19 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

An example of the getdefaultvaluelist script would look something like:

var dVLArray = [];
dVLArray[0]= "10104";
dVLArray[1] = "10108";
dVLArray;

This is for multi-select list box.

Jason

On 11/4/2010 12:06 PM, Bernie Durfee wrote:
> It looks like I can maybe do what I want using 'getdefaultvaluelist',
> but I can't find any examples. The values in the combo-box come from a
> data set, that returns a list of academic terms...
>
> TERM_CODE
> TERM_DESC
> TERM_START
> TERM_END
>
> ...the terms in the list include some past and some future terms. I want
> the current term selected by default. So in pseudo-code I figure I
> should be able to...
>
> Create array with default values
>
> Iterate through the values in the dataset to find the term code where
> today's date is between the term start and end dates
>
> Add the term code to the array so it becomes the default value
>
> ...I just don't know what's available within the context of the
> 'getdefaultvaluelist' call. Anyone want to get me started here?
Re: Default Dynamic Parameter [message #637262 is a reply to message #637258] Thu, 04 November 2010 18:27 Go to previous messageGo to next message
Bernie Durfee is currently offline Bernie Durfee
Messages: 6
Registered: October 2010
Junior Member
Thanks, that's a start. Now I need the values to be based on those from a DataSet. How do I iterate through the values in a DataSet named 'Term Codes'?
Re: Default Dynamic Parameter [message #637274 is a reply to message #637262] Thu, 04 November 2010 19:22 Go to previous messageGo to next message
Bernie Durfee is currently offline Bernie Durfee
Messages: 6
Registered: October 2010
Junior Member
I've been digging through the API's, I don't quite have a clear picture as to how they link together. A couple questions...

1) Where is getDefaultValueList defined in the API?

2) Is it possible to access rows of a data set from within getDefaultValueList?
Re: Default Dynamic Parameter [message #637455 is a reply to message #637274] Fri, 05 November 2010 15:02 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

Bernie,

We are looking at ways to improve this script because currently you have
very little access to current dataset. Two ways around this is to call
a custom java class to return the default list of values or call the
BIRT data engine. I am attaching an example that calls the birt data
engine to run a dataset that sets the default values.

What the script does is preselect all values in the list.

Jason

<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.22"
id="1">
<property name="createdBy">Eclipse BIRT Designer Version
2.6.1.v20100902 Build &lt;2.6.1.v20100915-1750></property>
<property name="units">in</property>
<property name="iconFile">/templates/blank_report.gif</property>
<property name="layoutPreference">auto layout</property>
<property name="bidiLayoutOrientation">ltr</property>
<parameters>
<scalar-parameter name="ListParameter3" id="21">
<property name="valueType">dynamic</property>
<property name="dataSetName">tiedtolist3</property>
<expression name="valueExpr"
type="javascript">dataSetRow["ORDERNUMBER"]</expression >
<expression
name="sortByColumn">dataSetRow["ORDERNUMBER"]</expression >
<property name="sortDirection">asc</property>
<property name="dataType">integer</property>
<property name="distinct">true</property>
<property name="paramType">multi-value</property>
<property name="controlType">list-box</property>
<property name="mustMatch">true</property>
<property name="fixedOrder">false</property>
<method name="getDefaultValueList"><![CDATA[try{

rsArr= [];

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.quer ydefn);
importPackage(Packages.org.eclipse.birt.data.engine.core);


var myconfig =
reportContext.getReportRunnable().getReportEngine().getConfi g();


var de = DataEngine.newDataEngine( myconfig, null );

var dsrc = reportContext.getDesignHandle().findDataSource("Data Source");
var dset = reportContext.getDesignHandle().findDataSet("tiedtolist3");

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 );


var ri = qr.getResultIterator( );
var cc = ri.getResultMetaData().getColumnCount();
var rsmd = ri.getResultMetaData();
var jj = 0;

while ( ri.next( ) )
{
rsArr[jj] = ri.getValue(rsmd.getColumnName(1)).toString();
jj++;

}

ri.close( );
qr.close( );
de.shutdown( );
}catch(e){
}
rsArr;]]></method>
<structure name="format">
<property name="category">Unformatted</property>
</structure>
</scalar-parameter>
</parameters>
<data-sources>
<oda-data-source
extensionID="org.eclipse.birt.report.data.oda.jdbc" name="Data Source"
id="7">
<list-property name="privateDriverProperties">
<ex-property>
<name>contentBidiFormatStr</name>
<value>ILYNN</value>
</ex-property>
<ex-property>
<name>metadataBidiFormatStr</name>
<value>ILYNN</value>
</ex-property>
</list-property>
<property
name="odaDriverClass">org.eclipse.birt.report.data.oda.sampledb.Driver </property>
<property name="odaURL">jdbc:classicmodels:sampledb</property>
<property name="odaUser">ClassicModels</property>
</oda-data-source>
</data-sources>
<data-sets>
<oda-data-set
extensionID="org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet "
name="tiedtolist3" id="22">
<list-property name="columnHints">
<structure>
<property name="columnName">ORDERNUMBER</property>
<text-property
name="displayName">ORDERNUMBER</text-property>
</structure>
<structure>
<property name="columnName">PRODUCTCODE</property>
<text-property
name="displayName">PRODUCTCODE</text-property>
</structure>
<structure>
<property name="columnName">QUANTITYORDERED</property>
<text-property
name="displayName">QUANTITYORDERED</text-property>
</structure>
<structure>
<property name="columnName">PRICEEACH</property>
<text-property
name="displayName">PRICEEACH</text-property>
</structure>
<structure>
<property name="columnName">ORDERLINENUMBER</property>
<text-property
name="displayName">ORDERLINENUMBER</text-property>
</structure>
</list-property>
<structure name="cachedMetaData">
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">ORDERNUMBER</property>
<property name="dataType">integer</property>
</structure>
<structure>
<property name="position">2</property>
<property name="name">PRODUCTCODE</property>
<property name="dataType">string</property>
</structure>
<structure>
<property name="position">3</property>
<property name="name">QUANTITYORDERED</property>
<property name="dataType">integer</property>
</structure>
<structure>
<property name="position">4</property>
<property name="name">PRICEEACH</property>
<property name="dataType">float</property>
</structure>
<structure>
<property name="position">5</property>
<property name="name">ORDERLINENUMBER</property>
<property name="dataType">integer</property>
</structure>
</list-property>
</structure>
<property name="dataSource">Data Source</property>
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">ORDERNUMBER</property>
<property name="nativeName">ORDERNUMBER</property>
<property name="dataType">integer</property>
<property name="nativeDataType">4</property>
</structure>
<structure>
<property name="position">2</property>
<property name="name">PRODUCTCODE</property>
<property name="nativeName">PRODUCTCODE</property>
<property name="dataType">string</property>
<property name="nativeDataType">12</property>
</structure>
<structure>
<property name="position">3</property>
<property name="name">QUANTITYORDERED</property>
<property name="nativeName">QUANTITYORDERED</property>
<property name="dataType">integer</property>
<property name="nativeDataType">4</property>
</structure>
<structure>
<property name="position">4</property>
<property name="name">PRICEEACH</property>
<property name="nativeName">PRICEEACH</property>
<property name="dataType">float</property>
<property name="nativeDataType">8</property>
</structure>
<structure>
<property name="position">5</property>
<property name="name">ORDERLINENUMBER</property>
<property name="nativeName">ORDERLINENUMBER</property>
<property name="dataType">integer</property>
<property name="nativeDataType">5</property>
</structure>
</list-property>
<xml-property name="queryText"><![CDATA[select *
from orderdetails]]></xml-property>
<xml-property name="designerValues"><![CDATA[<?xml
version="1.0" encoding="UTF-8"?>
<model:DesignValues
xmlns:design="http://www.eclipse.org/datatools/connectivity/oda/design"
xmlns:model="http://www.eclipse.org/birt/report/model/adapter/odaModel">
<Version>1.0</Version>
<design:ResultSets derivedMetaData="true">
<design:resultSetDefinitions>
<design:resultSetColumns>
<design:resultColumnDefinitions>
<design:attributes>
<design:name>ORDERNUMBER</design:name>
<design:position>1</design:position>
<design:nativeDataTypeCode>4</design:nativeDataTypeCode>
<design:precision>10</design:precision>
<design:scale>0</design:scale>
<design:nullability>Nullable</design:nullability>
<design:uiHints>
<design:displayName>ORDERNUMBER</design:displayName>
</design:uiHints>
</design:attributes>
<design:usageHints>
<design:label>ORDERNUMBER</design:label>
<design:formattingHints>
<design:displaySize>11</design:displaySize>
</design:formattingHints>
</design:usageHints>
</design:resultColumnDefinitions>
<design:resultColumnDefinitions>
<design:attributes>
<design:name>PRODUCTCODE</design:name>
<design:position>2</design:position>
<design:nativeDataTypeCode>12</design:nativeDataTypeCode>
<design:precision>15</design:precision>
<design:scale>0</design:scale>
<design:nullability>Nullable</design:nullability>
<design:uiHints>
<design:displayName>PRODUCTCODE</design:displayName>
</design:uiHints>
</design:attributes>
<design:usageHints>
<design:label>PRODUCTCODE</design:label>
<design:formattingHints>
<design:displaySize>15</design:displaySize>
</design:formattingHints>
</design:usageHints>
</design:resultColumnDefinitions>
<design:resultColumnDefinitions>
<design:attributes>
<design:name>QUANTITYORDERED</design:name>
<design:position>3</design:position>
<design:nativeDataTypeCode>4</design:nativeDataTypeCode>
<design:precision>10</design:precision>
<design:scale>0</design:scale>
<design:nullability>Nullable</design:nullability>
<design:uiHints>
<design:displayName>QUANTITYORDERED</design:displayName>
</design:uiHints>
</design:attributes>
<design:usageHints>
<design:label>QUANTITYORDERED</design:label>
<design:formattingHints>
<design:displaySize>11</design:displaySize>
</design:formattingHints>
</design:usageHints>
</design:resultColumnDefinitions>
<design:resultColumnDefinitions>
<design:attributes>
<design:name>PRICEEACH</design:name>
<design:position>4</design:position>
<design:nativeDataTypeCode>8</design:nativeDataTypeCode>
<design:precision>15</design:precision>
<design:scale>0</design:scale>
<design:nullability>Nullable</design:nullability>
<design:uiHints>
<design:displayName>PRICEEACH</design:displayName>
</design:uiHints>
</design:attributes>
<design:usageHints>
<design:label>PRICEEACH</design:label>
<design:formattingHints>
<design:displaySize>22</design:displaySize>
</design:formattingHints>
</design:usageHints>
</design:resultColumnDefinitions>
<design:resultColumnDefinitions>
<design:attributes>
<design:name>ORDERLINENUMBER</design:name>
<design:position>5</design:position>
<design:nativeDataTypeCode>5</design:nativeDataTypeCode>
<design:precision>5</design:precision>
<design:scale>0</design:scale>
<design:nullability>Nullable</design:nullability>
<design:uiHints>
<design:displayName>ORDERLINENUMBER</design:displayName>
</design:uiHints>
</design:attributes>
<design:usageHints>
<design:label>ORDERLINENUMBER</design:label>
<design:formattingHints>
<design:displaySize>6</design:displaySize>
</design:formattingHints>
</design:usageHints>
</design:resultColumnDefinitions>
</design:resultSetColumns>
</design:resultSetDefinitions>
</design:ResultSets>
</model:DesignValues>]]></xml-property>
</oda-data-set>
</data-sets>
<styles>
<style name="report" id="4">
<property name="fontFamily">"Verdana"</property>
<property name="fontSize">10pt</property>
</style>
<style name="crosstab" id="5">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
<style name="crosstab-cell" id="6">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
</styles>
<page-setup>
<simple-master-page name="Simple MasterPage" id="2">
<page-footer>
<text id="3">
<property name="contentType">html</property>
<text-property
name="content"><![CDATA[<value-of>new Date()</value-of>]]></text-property>
</text>
</page-footer>
</simple-master-page>
</page-setup>
</report>



On 11/4/2010 3:22 PM, Bernie Durfee wrote:
> I've been digging through the API's, I don't quite have a clear picture
> as to how they link together. A couple questions...
>
> 1) Where is getDefaultValueList defined in the API?
>
> 2) Is it possible to access rows of a data set from within
> getDefaultValueList?
Re: Default Dynamic Parameter [message #639220 is a reply to message #635155] Mon, 15 November 2010 16:28 Go to previous message
Bernie Durfee is currently offline Bernie Durfee
Messages: 6
Registered: October 2010
Junior Member
Oh! Here I thought this might be complicated... Razz

Here's what I came up with...

getDefaultValueList()

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);

// Grab the configuration object for the report engine
var myconfig = reportContext.getReportRunnable().getReportEngine().getConfig();

// Create a temporary data source based on the Banner data source
var dsrc = reportContext.getDesignHandle().findDataSource("Banner (PROD)");
  
var odaDataSource = new OdaDataSourceDesign( "Temporary 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", dsrc.getProperty("odaPassword").toString() );

// Create a temporary data set based on the term codes data set
var dset = reportContext.getDesignHandle().findDataSet("Term Codes");
  
var odaDataSet = new OdaDataSetDesign( "Temporary Data Set" );
odaDataSet.setDataSource( odaDataSource.getName( ) );
odaDataSet.setExtensionID("org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
odaDataSet.setQueryText( dset.getQueryText() );

// Instantiate a new data engine
var dataEngine = DataEngine.newDataEngine( myconfig, null );
dataEngine.defineDataSource( odaDataSource );
dataEngine.defineDataSet( odaDataSet );

// Create a new query definition using the data set
var queryDefinition = new QueryDefinition( );
queryDefinition.setDataSetName( odaDataSet.getName() );
queryDefinition.setAutoBinding(true);

// Prepare and execute the query
var pq = dataEngine.prepare( queryDefinition );
var queryResult = pq.execute( null );

// Setup an interator for the results
var resultIterator = queryResult.getResultIterator( );
  
// This will hold the default term code
var defaultTermCode = null;

var today = new Date().getTime();
  
while (resultIterator.next() && defaultTermCode == null) {
  var termCode = resultIterator.getString("STVTERM_CODE");
  var termStartDate = resultIterator.getDate("STVTERM_START_DATE").getTime();
  var termEndDate = resultIterator.getDate("STVTERM_END_DATE").getTime();

  //System.out.println("Code:" + termCode + "; Start: " + termStartDate + "; End: " + termEndDate);

  if(today >= termStartDate && today <= termEndDate) {
	defaultTermCode = termCode;
  }
}

resultIterator.close( );
queryResult.close( );
dataEngine.shutdown( );

// Return the default value
defaultTermCode;


...certainly could be simpler if I just had easy access to the data set associated with the parameter.
Previous Topic:How to create .rptdocument
Next Topic:Report output as text file
Goto Forum:
  


Current Time: Tue Sep 23 20:31:27 GMT 2014

Powered by FUDForum. Page generated in 0.02228 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software