6 Replies Latest reply on Aug 18, 2010 2:04 PM by oswaldlr843

    Calculation in an add instance

    oswaldlr843

      I am trying to use an if statement in an addinstance of an interactive form.  Based on the results of one field in the addinstance, I want to sum a different field from the add instance.  So, the customer can add any number of rows and choose from a drop down (coded 1-4) the position of the person.  If that position is 1 or 2, I want to sum the salary field in a calculation box.  If the position is 3, then I want to sum the salary(ies) in a second calcuation box, and if the position is 4, then I want to sum the salaries in a third calculation field.  My code for one of the the calculation field looks like this:

       


      form1.#subform[8].#subform[9].details.total.conditions.#subform[0].numTotal[

      1]::calculate - (FormCalc, client)

       

      if (detail[*].PTFT < 3) then

       

            Sum(detail[*].salary)

       

            endif

       

       

      The other two fields are the same except that they change "<3" to "==3" or "==4". 

       

      The problem is that it does not sum the second or third calcuation field.  Only my first calcuation field will work. 

       

       

      Since it is a rather simple if statement, I think that the problem may be in the subforms, possibly?

       

      Please see my form at http://www.units.muohio.edu/lifelonglearning/forms/zzztest.pdf

       

      Thanks in advance for any help you can lend.

        • 1. Re: Calculation in an add instance
          pguerett Level 6

          Ok I had a look at your form (nice form by the way ...good job). The expression you are using to determine the number of instances is not correct....as well when you sum the salaries it is the details subform that has th eiccurance numbers so that needs the * notation. Here is the 1st calc modified

           

          if  (details._detail.count < 3) then

               Sum(detail[*

           

          ].salary)

           

          endif

           

          You also have the same code on the layout ready and the calc event. No need for both ...just leave it on the calc event and when the user enters the amounts the totals will update.

           

          You are also getting an error when the row initialize .....a partNoScript is being called becuase of script behind the Name field (itis called txtPartNo in your form). My guess is that you copied this from the Purchase Order sample and forgot to remove the scritp from the Initialize and the change event. This field was originally a DD field and that is what was used to populate it.

           

          Hope that helps

          Paul

          • 2. Re: Calculation in an add instance
            oswaldlr843 Level 1

            Paul, Thanks so much, but not yet a go

              The code you suggest works, but does not give me the desired results.  Don't I have to use the detail.PTFT?  What is happening now is that if the first row details.detail.PTFT = 1 or 2 then it sums all the salaries in the MU employee salary box.  If details.detail.PTFT = 3, then it sums all the salaries in the MU student salary box.  I want it to evaluate each row individually based on that PTFT and sum in one of the two boxes.

             

            In words, I hope that:

            numTotal[1] = sum details.detail.salary where details.detail.PTFT < 3 for all instances of the table.

             

            Additional help?  Thanks so much Paul!

            • 3. Re: Calculation in an add instance
              pguerett Level 6

              I think I misunderstood what you are trying to do ....so if I select full or part time in the PTFT field I need to add all of those salaries into the 1st total. Then total up all of the benefits for the matching rows. Then I need to calculate the salaries of all rows where the user chose Student and calculate those salaries and benefits ....right?

               

              Paul

              • 4. Re: Calculation in an add instance
                oswaldlr843 Level 1

                Now you got what I am trying to accomplish.  Thanks so much

                 

                Lindsay R. Carpenter @ 9-8609

                • 5. Re: Calculation in an add instance
                  pguerett Level 6

                  Here is my concoction.....I removed the references to the partslist I mentioned earlier and I took a different approach to the addition of th efields. I had to use javascript because it allows a for loop which is required to accomplish the task. I wrapped the commands in an if statement to check if there are values in all three fields in the 1st row...other wise a number of errors is generated. You had a numch pf code on the layout ready events...I removed most of it as it was a duplicate of what was on the Calc event. There are still errors generated but I do not want to mess with what you already have. .....but it is working the way I think you want it.

                   

                  Let me know

                   

                  Paul

                  • 6. Re: Calculation in an add instance
                    oswaldlr843 Level 1

                    Paul, genius!  Exactly what I have struggled with for a week now.

                     

                    As you can see I am a self taught LiveCycle designer (mostly from the adobe forum questions/solutions.)

                     

                    Can't thank you enough.

                     

                    Best!