Expand my Community achievements bar.

SOLVED

Adding field values in multiple rows in a dynamic table

Avatar

Former Community Member

Hello!

I build this form (a timesheet) where I have a dynamic table with variable number of rows (I'm adding instances with a click on a button).

All rows contain a totalLinhaRelatorio field, this is a time field, and I need all such fields to be added to get a final total.

So I tried these two script lines (FormCalc):

var finalTotal = sum(Time2Num(parteInferior.atividades.tabelaAtividades.linhaAtividade[*].totalLinhaRelatorio[*],"HH:MM"))

$.formattedValue = Num2Time(finalTotal, "HH:MM")

It doesn´t work as I had expected. The field gets correctly just the value from the first row.

I've tried other combinations, such as linhaAtividade.totalLinhaRelatorio[*] and linhaAtividade[*].totalLinhaRelatorio but nothing seems to work.

Please, help!! 

Marcos

1 Accepted Solution

Avatar

Correct answer by
Level 10

You're welcome Marcos!

Yes, it is possible, but I have never used FormCalc for this, preferring JavaScript. Given that you are using time functions, it makes sense to stick with FormCalc.

Have a look at the syntax here:

http://help.adobe.com/en_US/livecycle/9.0/designerHelp/index.htm?content=000211.html.

Hope that helps,

Niall

View solution in original post

6 Replies

Avatar

Level 10

Hi Marcos,

I think that you will need to loop through the instances in FormCalc. The trouble I suspect is that you can't use the wildcard in the Time2Num function that is then wrapped within the sum function.

There is a discussion here on loops, albeit in JavaScript: http://www.assuredynamics.com/index.php/2011/05/som-expressions/.

Good luck,

Niall

Avatar

Former Community Member

Hi Niall,

Thank you once again! 

Now, all sample codes I've seen dealing with this looping use JavaScript. Is it possible to do the same with FormCalc?

Reason: the fields that must be added are time fields and it is a lot easier to work with FC than JS with those guys.

Marcos

Avatar

Correct answer by
Level 10

You're welcome Marcos!

Yes, it is possible, but I have never used FormCalc for this, preferring JavaScript. Given that you are using time functions, it makes sense to stick with FormCalc.

Have a look at the syntax here:

http://help.adobe.com/en_US/livecycle/9.0/designerHelp/index.htm?content=000211.html.

Hope that helps,

Niall

Avatar

Former Community Member

Hi Niall,

I've just given up trying to figure out how FormCalc treats time calculations and will do it in JS. Thus your material will come in really handy!

Thank you!

Yes, I will have to create my own time calculation functions, no big deal.

What I still haven't figured out, thoughm, is how to cast strings into integers in JS. Should be as simple as parseInt() or Number(), but for some reason its not working.

Marcos

Avatar

Level 10

Hi Marcos,

The loop is possible, its just that I have never gone down the FormCalc route.

Also, the Number() works for me. For example, where I am referencing a string variable in a function:

return Number(cleanedTextField);

Try an console.println() before and after the line of script and see what is happening in the JavaScript Console.

Good luck,

Niall

Avatar

Former Community Member

Ha! it worked!! Please, don't ask...

Now, yes, the loop works perfecly in FormCalc; only the time field calculations in FC is really weird, so I will be better off writing my own function and using your excellent material on SOM Expressions!

Thank you so much!

Marcos