9 Replies Latest reply on Apr 1, 2013 3:33 PM by darje6666

    Repetable row trouble with auto sum

    darje6666

      Hi,

       

      I'm really struggling with this table. Please take a look.

       

      What I want is to have fields Komada, m2, Iznos be summed up in a corresponding total field thats underneath the table.

       

      The trouble is I made a button that adds or substracts new table rows. Please check it in LC Designer so I understand your suggestions.

       

      The form is here.

      udrugasasrcem.com/test4.pdf

       

       

      Thanks

        • 1. Re: Repetable row trouble with auto sum
          Mandy_Wiesener Level 3

          The solution is very simple.

          • You have to use this script in the calculate-event of your target field (nomally in the table footer). You have to use Formcalc.
          • If you create instances of the row your code have to be:
          • If the name of your row is another you have to adpt htis.
          • If the name of your amount field another you have to adapt this.
          • I think this is the version which you need then you create instances of the row. But I can't help because I can't see which field is a amount field in your pdf
          $ = Sum(Row1[*].amount) //in your pdf maybe $ = Sum(Row1[*].iznos) 

           

          If you create instances of the amont field you have to write

          $ = Sum(amount[*]) 

           

          If you want to make an addition you can insert a table footer. There you can make an addition of each field. And in your target field you can use the following:

          $ = Sum(Total_iznos, Total_m2, Total._kommanda)
          

           

          This row you can set to hidden or invisible if you want not to see this.

           

          Hope it will help,
          Mandy

          1 person found this helpful
          • 2. Re: Repetable row trouble with auto sum
            darje6666 Level 1

            Thanks, but that doesnt solve my problem quite yet. I need that field to recalculate every time i enter a new value in the above cells. I'll explain.

             

            So the fields in question are.

             

            sirina * visina * visina = m2

            m2 * cijena = iznos

            komada

             

            All those 3 bolded fields have a corresponding total field underneath them.

             

            So if I add a new row or change an existing one it should reflect on the values of m2, iznos and komada in the single row and ukupnom2, ukupnoiznos and ukupnokomada in the total row next to the letters UKUPNO:

             

            Hope this clarifies it. Here's an updated version of the PDF with your instructions.

            udrugasasrcem.com/test4.pdf

            • 3. Re: Repetable row trouble with auto sum
              darje6666 Level 1

              Hm I think I almost got it.

               

              I added this to calculate event on the 3 total fields (just replace iznos with m2 and komada for the other 2).

              var sum = 0;

              var columnArray = xfa.resolveNodes( "master.Table3.Row1[*].iznos");

              for( var i = 0; i<columnArray.length; i++)

              {

                  sum += columnArray.item(i).rawValue;

              }

              this.rawValue = sum;

               

              And then I added this to Table3.Row1 indexChange event.

               

              // Revalue the weight if we delete one of the subform instances or add another subform in the middle

              this.rawValue = this.parent.instanceIndex + 1;

               

              // Fix for listener problem

              master.Table3.Row1.execCalculate();

               

              But the problem is... it recalculates the values for the first row. But when I add the second it doesnt add it to the total fields.

               

              Here's that version of the PDF.

              udrugasasrcem.com/test5.pdf

              • 4. Re: Repetable row trouble with auto sum
                Mandy_Wiesener Level 3

                If you use this script

                ($ = Sum(amount[*]))
                

                in the calculate-event the calculate always recalculate if one of the parameter in the SUM function is changing his value.

                 

                xfa.resolveNodes( "master.Table3.Row1[*].iznos"); --> The [] aren't NO a sign for an array. This square brackets are only from the instances. But it's ok you used it as a name of the varibale.

                 

                I don't use execCalculate(); because this is not so good for the performance in my opinion. Normally everything is working fine with the calculate.event.

                 

                Let me see the next days. I will take a look to your pdf when I have more time.

                 

                Kind regards

                Mandy

                 

                **********

                PS:

                In the calculate-event (using Formcalc) of the Footer from Komada use

                 

                $ = Sum(Row1[*].komada)
                

                 

                In the calculate-event (using Formcalc) of the Footer from m2 use

                $ = Sum(Row1[*].m2)
                

                 

                In the calculate-event (using Formcalc) of the Footer from iznos use

                $ = Sum(Row1[*].iznos)
                

                 

                This all three works correct!

                 

                The problem in your script is-..there are a few mistakes...you use in Formcalc "this". "This" you could only use by Javascript. The same in Formcalc is "$"...

                You used too much brackets, for example here..you don't neefd TWO brackets!

                else if ((this.resolveNode("$").rawValue !== null || this.resolveNode("$").rawValue !== "")) {
                
                1 person found this helpful
                • 5. Re: Repetable row trouble with auto sum
                  darje6666 Level 1

                  Thanks on the clarification but it still doesnt work. Ok I will wait for you. Thank you very much for your time.

                  • 6. Re: Repetable row trouble with auto sum
                    darje6666 Level 1

                    Here I'll make it easier for you to track down the problem. Made a new table at the bottom with a single row and the ability to add or substract new rows.

                    So if you could check that markup. Cause the recalculation works only for the first row. And it also works when you add new rows and insert some numbers in there but then you have to change the number in the first row for it to recalculate all of the rows.

                    Here's the PDF.udrugasasrcem.com/test6.pdf

                    • 7. Re: Repetable row trouble with auto sum
                      darje6666 Level 1

                      I really dont get it. It works in Adobe Reader but not in Foxit. Im really desperate. Have a deadline this wendesday.

                      • 8. Re: Repetable row trouble with auto sum
                        Mandy_Wiesener Level 3

                        It works only in Adobe Reader. Other viewer cant show correct PDFs, static PDFs is ok ut a PDF with calculation an dynamics...you have to use the Adobe Reader!!!

                         

                        But this is not the problem from Adobe and LCD. Thsi is the problem of the third party supplier(s).

                         

                        Kind regards Mandy

                        • 9. Re: Repetable row trouble with auto sum
                          darje6666 Level 1

                          Ah darn it. Is there a workaround for this? Some other function or something? Please...