Expand my Community achievements bar.

Looping through Iterative section

Avatar

Level 2

Hi All,

I need help in writing the java script for looping through the iterative section.

I have asset table, which has asset name ,desc and cost. Each asset section also has 'asset_include' value which can be 'Y' or 'N'.

The iterative data should display only if the asset_include value is 'Y' . How do I loop through the iterative sction and display only if its 'Y'

Example: I have 3 Iterative sections;

<Assets>

     <asset_name>TV</asset_name>

     <asset_desc>Television</asset_desc>

     <asset_cost>50000</asset_cost>

     <asset_include>Y</asset_include>

</Assets>

<Assets>

     <asset_name>Mobile</asset_name>

     <asset_desc>Mobile</asset_desc>

     <asset_cost>30000</asset_cost>

     <asset_include>Y</asset_include>

</Assets>

<Assets>

     <asset_name>Book</asset_name>

     <asset_desc>Book</asset_desc>

     <asset_cost>100</asset_cost>

     <asset_include>N</asset_include>

</Assets>

Output should display only TV and Mobile but not Book.

Its very urgent can some one help me?

6 Replies

Avatar

Former Community Member

Are you referring to merging data and rendering rows in a table only if asset_include is "Y" OR are you referring to iterating through the XML with script to dynamically render the table only if asset_include is "Y"?

Steve

Avatar

Level 2

Hi

i am reffering to iterating through xml .

i have a table in my design and 1 row is set to iterative.

When i have more than 1 asset-include with value 'y' i would like display that assets value.

I think i need to use instance manager to get all the instances and write for loop

to go through each asset-include valie.

Please help me in writing for loop or if u have an idea to implement this.

Thanks steve

Avatar

Level 5

Hi,

If you are using a table I don't think you need to iterate over all the instances, you could use an event on a cell in the table to do the work for you.

Assuming you are showing all the data you could do something where in the "initialise" event of the cell which contains the "assetInclude" value you could have code something like

FileData.#subform[0].Table1.Row1.asset_include::initialize - (JavaScript, client)

   

if ( this.rawValue == "N")

{

          this.parent.presence = "hidden";

}

If the tables row are set to repeat for each data item then you will only get the entries in the data which have an assetinclude value of Y. in this example.

Hope this helps

Malcolm

Avatar

Level 2

Hi..

I am not showing asset_include in my table. I have 3 columns for name ,desc and cost. Based on asset_include value I am displaying entire row which has these 3 values.

So I cant write script at asset_include.

Avatar

Level 5

HI,

Can you upload your document to acrobat.com ( or some other sharing site) and post the link here and then we can work from your sample so you can see what we have changed and this will hopefully help your understanding. It will also enable us to make sure we are working in the same manner as you are.

I think based on your response it would work if you added a field to one of the columns of your table so that you have say asset_cost and asset_include in the same column, have these both with bindings to their relative data items, then you could place the script on the asset_include and also include a script to hide the asset_include and therefore your table would look as you would like and you would be able to use the script provided.

In this case your script would be something like

if ( this.rawValue == "N")

{

     // hide the row containing asset_include == N

          this.parent.presence = "hidden";

}

// hide the asset_include field

this.presnce = "hidden";

As stated above if you up load the sample we can look at that and suggest changes that way, perhaps modifying the document and sharing it back.

Regards

Malcolm