Expand my Community achievements bar.

SOLVED

FormCalc/Script query?

Avatar

Level 2
Start Time
End Time
Mode of Transport
Journey Time
HH:MMHH:MMDrop Down ListAuto calculated on start/end times

Total Time Traveling
Sum of Journey Times

Mode of Transport
Total Time Journey Time
Drop Down List

I have created an interactive form which requires members of the general public to fill out a travel diary. I have got all the calculations to work except the bottom table. I'm trying to figure out which formcalc scripts to use to give a total time for each mode of transport, based on the users choice. For example, if the user want's to see how many mins they have cycled this week, they pick cycling from the drop down list on the bottom table and then in the total journey time it tells them how many mins they have cycled that week.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

I am all for learning and hope that this returned form helps. But a little annoyed that Managers do not "appear" be place a value on it.

https://acrobat.com/#d=HJIBeWz3ZjvcBZjsSW-Vrw

I have sorted out the first two pages, in how I believe it would be best to approach the problem:

  1. I have deleted the rows and just kept one row which is repeatable (see Object > Binding palette). This is easier to maintain, as all of the script is in one row. The row is then set to have a minimum of 10 occurrences.
  2. I have also included tool tips in the fields for accessibility. Local Authority and all.
  3. You should name objects based on their role. This makes it much easier to script against. See here: http://assure.ly/mxZO9T.
  4. I have inserted a page and table for the summary. I have taken an approach where all of the categories would be visible and the corresponding times. I have also includes a bar chart. You could colour each bar based on the greenness of the mode of transport.
  5. You need to look at the script in the summary times. This loops through the first two pages AND loops through each of the 10 rows in each of these tables.

Looping script for anyone interested:

// Set up some variables

var vTime = 0;

var currentRow;


// Calculate a summary for car

for (var i=3; i<5; i++) // work through the first two pages

{

     for (var j=0; j<10; j++) // work through the ten rows in each page

     {

          currentRow = xfa.resolveNode("Page" + i + ".Table1.Row1[" + j + "]");

          if (currentRow.modeTransport.rawValue == "Car")

          {

               vTime = vTime + currentRow.journeyTime.rawValue;

          }

     }

}


// Set summary journey time

this.rawValue = vTime / 60;

Hopefully your manager will see value!

Niall

View solution in original post

11 Replies

Avatar

Level 10

Hi,

Is the top table dynamic, in that the user can add more rows?

One way would be to have script in the exit event of the summary table dropdown, that would loop through all of the rows in the top table and if the dropdown in a row matches it would add that time.

If we take that the rows are repeatable then the following JavaScript should help:

var nRows = Table1._Row1.count;

var vTime = 0;

var currentMode;

// loops through the table

for (var 1=0; i<nRows; i++)

{

     // resolve the first table dropdown

     currentMode = xfa.resolveNode("Table1.Row1[" + i + "].modeTransport").rawValue;

     // if this is same as user selection in summary table then add

     if (currentMode == this.rawValue)

     {

          vTime = vTime + currentMode;

     }

}

// set total time in same row as dropdown in summary table

TotalTime.rawValue = vTime;

There are a couple of table solutions that may help: http://assure.ly/lwQHm7

Hope that helps,

Niall

Avatar

Level 2

Thanks for the reply, it was very useful!

I don't think I gave enough info...as I am quite new to livecycle and new to this project.

http://www.2shared.com/document/MdBLfjgr/travelDiary_FINAL_2011.html is what I'm working on, the password is travel2011

Cheers,

L.

Avatar

Level 10

It's like all journeys: "well I wouldn't start from here" ;-)

It doesn't appear that you have a summary table yet. Is that correct?

I will work up a solution, but will take some rows out.

Fear not,

Niall

Avatar

Level 10

Hmmm, also on two tables you have a start time and a finish time, whereas on others you have a start time and journey time. Which are you running with?

Niall

Avatar

Level 2

You're right, I haven't done the summary table yet, just because I like to get the basic scripts/formulae correct first and then play around where they are going to go.

As you'll see, the first couple of days have been done in terms of the table above, but once all the scripts are done, then I'll change all the other tables.

For example, I did a lot of the scripts for days one and two, and at the moment they are my test pages. Once, I've got those sorted, I can edit the summary script for all the other days and implement it for days 3,4,5,6 and 7.

L.

Avatar

Level 2

Oh, also, because the project doesn't go live till July, my manager may want other things included (or changed), which she is too tight to pay our own IT guys to do and wants me to learn it .

L.

Avatar

Correct answer by
Level 10

Hi,

I am all for learning and hope that this returned form helps. But a little annoyed that Managers do not "appear" be place a value on it.

https://acrobat.com/#d=HJIBeWz3ZjvcBZjsSW-Vrw

I have sorted out the first two pages, in how I believe it would be best to approach the problem:

  1. I have deleted the rows and just kept one row which is repeatable (see Object > Binding palette). This is easier to maintain, as all of the script is in one row. The row is then set to have a minimum of 10 occurrences.
  2. I have also included tool tips in the fields for accessibility. Local Authority and all.
  3. You should name objects based on their role. This makes it much easier to script against. See here: http://assure.ly/mxZO9T.
  4. I have inserted a page and table for the summary. I have taken an approach where all of the categories would be visible and the corresponding times. I have also includes a bar chart. You could colour each bar based on the greenness of the mode of transport.
  5. You need to look at the script in the summary times. This loops through the first two pages AND loops through each of the 10 rows in each of these tables.

Looping script for anyone interested:

// Set up some variables

var vTime = 0;

var currentRow;


// Calculate a summary for car

for (var i=3; i<5; i++) // work through the first two pages

{

     for (var j=0; j<10; j++) // work through the ten rows in each page

     {

          currentRow = xfa.resolveNode("Page" + i + ".Table1.Row1[" + j + "]");

          if (currentRow.modeTransport.rawValue == "Car")

          {

               vTime = vTime + currentRow.journeyTime.rawValue;

          }

     }

}


// Set summary journey time

this.rawValue = vTime / 60;

Hopefully your manager will see value!

Niall

Avatar

Level 2

Hi Niall,

Thanks for the reply. I'll have a look at it now. It's not that my manager doesn't see the value, it's the fact we have a small budget for this project and trying to save where she can. She would rather spend the amount this would have cost, for me to spend half a day (which is the same amount of time of IT guys would have charged us for to make changes to this travel diary) with our database guy so I can fix things cheaper in the future.

L.

Avatar

Level 2

Hey Niall,

Thanks so much! It's perfect :). I'll show it to you when it's complete .

Just to check, do I copy and paste the tables from page 1 and 2 onto the other pages?

Cheers,

M.

Avatar

Level 10

Hi,

Yes, you would need to copy the solution down to the other five days.

The easiest way is to select Row1 in the first table and copy (Control+C). Then in the other tables, select the first instance of Row1 and paste (Control+V). You will need to delete the redundant Rows.

This will bring all of the objects and scripts to the other tables.

The summary script will need to be altered to loop to Page9. E.g. using "i<10", the last loop will be i=9 and the script will use this as "Page9".

for (var i=3; i<10; i++) // work through the first seven pages

Should be good to go then.

Niall