Skip to main content



      Home
Home » Archived » BIRT » scripted nested loop examples
scripted nested loop examples [message #360500] Tue, 05 February 2008 04:45 Go to next message
Eclipse UserFriend
Originally posted by: assaf.frank.dynasec.org

Hi,

My report contains several nested loops in them (for example - fathers -
sons relationships). How can I display these nested loops in a single
fetch script method ? Where can I find examples for this ?

Thanks very much.
Re: scripted nested loop examples [message #360506 is a reply to message #360500] Tue, 05 February 2008 10:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jasonweathersby.alltel.net

It may be better to do two scripted data sets. One for the the father
elements and one for the child elements. In the child script you would
accept the father as a dataset parameter and in the report you would add
a table for the father dataset and a nested table for the child elements.

Jason

assaf wrote:
> Hi,
>
> My report contains several nested loops in them (for example - fathers -
> sons relationships). How can I display these nested loops in a single
> fetch script method ? Where can I find examples for this ?
>
> Thanks very much.
>
Re: scripted nested loop examples [message #360546 is a reply to message #360506] Thu, 07 February 2008 09:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: assaf.frank.dynasec.org

Thanks Jason.

I tried doing this but I guess I'm not doing the right steps-
Can you describe the exact steps for this or is there a sample you can
forward me for this that describes the steps ?

(Do I create an out parameter on the father dataset ? Or only an in
parameter
in the son dataset and bind it somehow to a column from the father? How do
I in the son dataset reference the parameter passed by the father dataset).

Many thanks in advance!
Re: scripted nested loop examples [message #360550 is a reply to message #360546] Thu, 07 February 2008 10:15 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jasonweathersby.alltel.net

Take a look at this example.

It is contrived, but you should get the idea. I am using an input
parameter on the inner data set. Also look at the initialize method to
see how the data is set up.

Jason

<?xml version="1.0" encoding="UTF-8"?>
<!-- Written by Eclipse BIRT 2.0 -->
<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.6"
id="1">
<property name="createdBy">Eclipse BIRT Designer Version
2.1.2.v20070205-1728 Build &lt;20070205-1728></property>
<property name="units">in</property>
<property name="comments">Copyright (c) 2006 &lt;&lt;Your Company
Name here>></property>
<method name="initialize"><![CDATA[importPackage( Packages.java.util );
importPackage( Packages.java.lang );

var outerMap = new Hashtable();
var innerMap = new Hashtable();

for ( i=0; i<10; i++ ){
var mystring = "Outerrow_" + i;
var myinnerstring = "Innerrow_" + i;
outerMap.put(i, mystring);
innerMap.put( mystring, myinnerstring );
}
reportContext.setPersistentGlobalVariable("outerMap", outerMap);
reportContext.setPersistentGlobalVariable("innerMap", innerMap);]]></method>
<data-sources>
<script-data-source name="Data Source" id="4"/>
</data-sources>
<data-sets>
<script-data-set name="outer" id="5">
<list-property name="resultSetHints">
<structure>
<property name="position">0</property>
<property name="name">outtercol</property>
<property name="dataType">string</property>
</structure>
</list-property>
<list-property name="columnHints">
<structure>
<property name="columnName">outtercol</property>
</structure>
</list-property>
<structure name="cachedMetaData">
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">outtercol</property>
<property name="dataType">string</property>
</structure>
</list-property>
</structure>
<property name="dataSource">Data Source</property>
<method name="open"><![CDATA[hMap =
reportContext.getPersistentGlobalVariable("outerMap");
iter = hMap.entrySet().iterator();]]></method>
<method name="fetch"><![CDATA[if( iter.hasNext() ){
myObject = iter.next();
row["outtercol"] = myObject.getValue().toString();
return true;

}else{

return false;

}]]></method>
</script-data-set>
<script-data-set name="inner" id="6">
<list-property name="resultSetHints">
<structure>
<property name="position">0</property>
<property name="name">innercol</property>
<property name="dataType">string</property>
</structure>
</list-property>
<list-property name="columnHints">
<structure>
<property name="columnName">innercol</property>
</structure>
</list-property>
<structure name="cachedMetaData">
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">innercol</property>
<property name="dataType">string</property>
</structure>
</list-property>
</structure>
<property name="dataSource">Data Source</property>
<list-property name="parameters">
<structure>
<property name="name">innerparm</property>
<property name="dataType">string</property>
<property name="position">1</property>
<expression name="defaultValue">testkey</expression>
<property name="isInput">true</property>
<property name="isOutput">true</property>
</structure>
</list-property>
<method name="open"><![CDATA[i = 0;
jj = inputParams["innerparm"];]]></method>
<method name="fetch"><![CDATA[iMap =
reportContext.getPersistentGlobalVariable("innerMap");
inObj = iMap.get(jj);
if( i > 0 )return false;

if( inObj != null ){
row["innercol"] = inObj.toString();

}
i++
return true;]]></method>
</script-data-set>
</data-sets>
<styles>
<style name="detail" id="54">
<property name="backgroundColor">#BACAE2</property>
<property name="fontFamily">Arial</property>
<property name="fontSize">small</property>
<property name="paddingTop">0px</property>
<property name="paddingLeft">0px</property>
<property name="paddingBottom">0px</property>
<property name="paddingRight">0px</property>
</style>
<style name="headerfooter" id="55">
<property name="backgroundColor">#004080</property>
<property name="fontFamily">Arial</property>
<property name="fontSize">small</property>
<property name="fontWeight">bold</property>
<property name="color">#FFFFFF</property>
</style>
<style name="groupheader" id="56">
<property name="backgroundColor">#0080FF</property>
<property name="fontFamily">Arial</property>
<property name="fontSize">small</property>
<property name="fontWeight">bold</property>
<property name="color">#FFFFFF</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>
<body>
<table id="7">
<property name="width">100%</property>
<property name="dataSet">outer</property>
<list-property name="boundDataColumns">
<structure>
<property name="name">outtercol</property>
<expression
name="expression">dataSetRow["outtercol"]</expression>
<property name="dataType">string</property>
</structure>
</list-property>
<column id="16"/>
<column id="20"/>
<header>
<row id="8">
<property name="style">headerfooter</property>
<cell id="9">
<label id="10">
<text-property
name="text">OuterDSCol</text-property>
</label>
</cell>
<cell id="17"/>
</row>
</header>
<detail>
<row id="11">
<property name="style">detail</property>
<cell id="12">
<data id="13">
<property
name="resultSetColumn">outtercol</property>
</data>
</cell>
<cell id="18">
<table id="21">
<property name="width">100%</property>
<property name="dataSet">inner</property>
<list-property name="paramBindings">
<structure>
<property
name="paramName">innerparm</property>
<expression
name="expression">row["outtercol"]</expression>
</structure>
</list-property>
<list-property name="boundDataColumns">
<structure>
<property
name="name">innercol</property>
<expression
name="expression">dataSetRow["innercol"]</expression>
<property
name="dataType">string</property>
</structure>
</list-property>
<column id="30"/>
<header>
<row id="22">
<cell id="23">
<label id="24">
<text-property
name="text">InnerDataSetCol</text-property>
</label>
</cell>
</row>
</header>
<detail>
<row id="25">
<property
name="style">groupheader</property>
<cell id="26">
<data id="27">
<property
name="resultSetColumn">innercol</property>
</data>
</cell>
</row>
</detail>
</table>
</cell>
</row>
</detail>
<footer>
<row id="14">
<property name="style">headerfooter</property>
<cell id="15"/>
<cell id="19"/>
</row>
</footer>
</table>
</body>
</report>


assaf wrote:
> Thanks Jason.
>
> I tried doing this but I guess I'm not doing the right steps-
> Can you describe the exact steps for this or is there a sample you can
> forward me for this that describes the steps ?
>
> (Do I create an out parameter on the father dataset ? Or only an in
> parameter
> in the son dataset and bind it somehow to a column from the father? How
> do I in the son dataset reference the parameter passed by the father
> dataset).
>
> Many thanks in advance!
>
Re: scripted nested loop examples [message #360564 is a reply to message #360550] Fri, 08 February 2008 02:52 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: assaf.frank.dynasec.org

Many thanks Jason , this works and I get the idea.

I also managed to solve this problem by using the session object of the
report
to store the current father_id (in the father fetch) to be used in the son
open method..

Is there a prefered way between the two (session vs. param binding) ?

Thanks.
Re: scripted nested loop examples [message #360568 is a reply to message #360564] Fri, 08 February 2008 10:49 Go to previous message
Eclipse UserFriend
Originally posted by: jasonweathersby.alltel.net

I believe that either way is acceptable.

Jason

assaf wrote:
> Many thanks Jason , this works and I get the idea.
>
> I also managed to solve this problem by using the session object of the
> report
> to store the current father_id (in the father fetch) to be used in the
> son open method..
>
> Is there a prefered way between the two (session vs. param binding) ?
>
> Thanks.
>
Previous Topic:Predefining Categories
Next Topic:Margins as % doesnt work
Goto Forum:
  


Current Time: Mon Nov 03 04:27:55 EST 2025

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

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

Back to the top