36 Replies Latest reply on Apr 25, 2016 2:53 PM by try67

    Calculation

    lvp1920

      I am making a form and need to have certain "total" fields automate to the totals page. I am new at this so I'm not quite sure what I am doing.  More specifically,  if "H" is chosen in the dropdown, the value field that is next to it needs to automatically fill in on the totals page.

       

      Hopefully this makes sense.

        • 1. Re: Calculation
          gkaiseril MVP & Adobe Community Professional

          You have to be very clear on what you want.

           

          It sounds like you want a single field's value to go to a field on another field. Since this action requires the testing of a condition it can only be done using  custom JavaScript for an action. There are many actions for any given field. If the field that could hold this value is only filled with the selected value I would use the calculation for that field on the totals page so I would have both the check box for control and the value. You need to provide the various field names.

          • 2. Re: Calculation
            lvp1920 Level 1

            Field name "BankOwner" (if person chooses "JTS") the dollar amount in Field: "Amount1" should automatically split between fields: "Husband1" and "Wife1".

            • 3. Re: Calculation
              try67 MVP & Adobe Community Professional

              And if it's something else, what should be the value of those fields?

              • 4. Re: Calculation
                lvp1920 Level 1

                Below is what I am working on to give a better idea.

                 

                Capture3.PNGCapture7.PNG

                • 5. Re: Calculation
                  try67 MVP & Adobe Community Professional

                  That doesn't really answer my question above...

                  • 6. Re: Calculation
                    lvp1920 Level 1

                    I'm not sure what you're asking.

                    • 7. Re: Calculation
                      try67 MVP & Adobe Community Professional

                      You wrote that if the user chooses "JTS" under BankOwner then the amount should be split between the Husband and Wife fields. OK, that's clear. But what should be the value of these fields if the user selected a different value under BankOwner? Should they just be blank? Zero? Something else?

                      • 8. Re: Calculation
                        lvp1920 Level 1

                        Oh, okay. If the user chooses "H" or "W" the amount they put in the "Amount" field should automatically populate in their corresponding column on the Summary of Values page. In other words, if the user chooses "H" for "Owner" and has $150.00 in the "amount" field, then $150 should automatically show up under the Husband column in the row of "Bank and Savings Accounts".

                        • 9. Re: Calculation
                          try67 MVP & Adobe Community Professional

                          And what about the "Wife" field, then?

                          • 10. Re: Calculation
                            lvp1920 Level 1

                            The "wife" field should remain empty, or total $0.00

                            • 11. Re: Calculation
                              try67 MVP & Adobe Community Professional

                              How do you know that the amount belongs to the husband and not the wife? I can imagine some people finding this assumption quite offensive.

                              • 12. Re: Calculation
                                lvp1920 Level 1

                                They are the ones filling out the form. If it is jointly owned money then they would choose "JTS" as the owner. However, if they have individually owned accounts they would choose either "H" or "W."  That is how they would know if they amount belongs to the husband or wife.

                                • 13. Re: Calculation
                                  lvp1920 Level 1

                                  Do you know how I would calculate this?

                                  • 14. Re: Calculation
                                    try67 MVP & Adobe Community Professional

                                    Use this code as the custom calculation script of "Husband 1":

                                    var amount = Number(this.getField("Amount 1").value);
                                    var owner = this.getField("Bank Owner 1").valueAsString;
                                    if (owner=="H") event.value = amount;
                                    else if (owner=="W") event.value = 0;
                                    else if (owner=="JTS") event.value = amount/2;
                                    else event.value = "";
                                    

                                     

                                    And this code as the custom calculation script of "Wife 1":

                                    var amount = Number(this.getField("Amount 1").value);
                                    var owner = this.getField("Bank Owner 1").valueAsString;
                                    if (owner=="H") event.value = 0;
                                    else if (owner=="W") event.value = amount;
                                    else if (owner=="JTS") event.value = amount/2;
                                    else event.value = "";
                                    
                                    • 15. Re: Calculation
                                      lvp1920 Level 1

                                      Wonderful thanks so much!

                                       

                                      How would I get the "Summary of Values" to add all 3 amounts? (Amount 1, Amount 2, Amount 3)

                                      • 16. Re: Calculation
                                        gkaiseril MVP & Adobe Community Professional

                                        Look at the "Calculation" tab. You can use any of the 3 options for the calculation. For the Simplified Field Notation and the custom JavaScript you need to comply with the naming conventions and syntax for the option selected

                                        • 17. Re: Calculation
                                          lvp1920 Level 1

                                          I am using the custom option and the code that try67 made works fine. I just need it to add all three amounts, not just one.

                                          • 18. Re: Calculation
                                            lvp1920 Level 1

                                            This is the calculation that I am using, how would I add "market2"

                                             

                                            var amount = Number(this.getField("Market1").value); 

                                            var owner = this.getField("RealProp1").valueAsString; 

                                            if (owner=="H") event.value = 0;

                                            if (owner=="H - JTO") event.value = 0; 

                                            else if (owner=="W") event.value = amount;

                                            else if (owner=="W - JTO") event.value = amount;

                                            else if (owner=="JTS") event.value = amount/2; 

                                            else event.value = ""; 

                                            • 19. Re: Calculation
                                              try67 MVP & Adobe Community Professional

                                              var amount = Number(this.getField("Market1").value) + Number(this.getField("Market2").value);

                                               

                                              And you should add an "else" before the second if-statement.

                                              • 20. Re: Calculation
                                                lvp1920 Level 1

                                                For some reason it is not working correctly. I attached pictures to show you. When "W" is chosen, $100.00 should show up in the Wife total field but for some reason it is all going to the husband field.

                                                total field.Capture1.PNGCapture.PNG

                                                • 21. Re: Calculation
                                                  try67 MVP & Adobe Community Professional

                                                  Post your current code. Also, press Ctrl+J to open the JS Console and make sure there are no error messages there.

                                                  • 22. Re: Calculation
                                                    lvp1920 Level 1

                                                    I have this for the husband field in "summary of values"

                                                     

                                                    var amount = Number(this.getField("Market1").value) + Number(this.getField("Market2").value) + Number(this.getField("Market3").value)

                                                    var owner = this.getField("RealProp1").valueAsString;

                                                    if (owner=="W") event.value = 0;

                                                    else if (owner=="W - JTO") event.value = 0;

                                                    else if (owner=="H") event.value = amount;

                                                    else if (owner=="H - JTO") event.value = amount;

                                                    else if (owner=="JTS") event.value = amount/2;

                                                    else event.value = "";

                                                     

                                                     

                                                     

                                                    and this for the wife field in "summary of values"

                                                     

                                                    var amount = Number(this.getField("Market1").value) + Number(this.getField("Market2").value) + Number(this.getField("Market3").value)

                                                    var owner = this.getField("RealProp1").valueAsString;

                                                    if (owner=="H") event.value = 0;

                                                    else if (owner=="H - JTO") event.value = 0;

                                                    else if (owner=="W") event.value = amount;

                                                    else if (owner=="W - JTO") event.value = amount;

                                                    else if (owner=="JTS") event.value = amount/2;

                                                    else event.value = "";

                                                    • 23. Re: Calculation
                                                      lvp1920 Level 1

                                                      This is what it shows

                                                      Capture2.PNG

                                                      • 24. Re: Calculation
                                                        lvp1920 Level 1

                                                        you have been so helpful, I really appreciate your time!

                                                        • 25. Re: Calculation
                                                          try67 MVP & Adobe Community Professional

                                                          You need to scroll up the console window a bit... There's something there but it's not visible.

                                                          It might also be helpful if you could share the actual file (via Dropbox, Google Drive, etc.).

                                                          • 26. Re: Calculation
                                                            lvp1920 Level 1

                                                            I can do that, what email address should I share it with?

                                                            • 27. Re: Calculation
                                                              lvp1920 Level 1
                                                              • 28. Re: Calculation
                                                                try67 MVP & Adobe Community Professional

                                                                It's not public, so I requested permission to download it (try6767 at gmail).

                                                                • 29. Re: Calculation
                                                                  lvp1920 Level 1

                                                                  Should be good now. Let me know if you're having trouble viewing it.

                                                                  • 30. Re: Calculation
                                                                    try67 MVP & Adobe Community Professional

                                                                    OK, I had a look at the file. Open the JS Console and you'll see these error messages:

                                                                    TypeError: f is null

                                                                    This is a problem. It means that somewhere you're using a wrong field name. Unfortunately, it's most likely a part of an automatic calculation (like when you use the Sum function in the Calculate tab), but there are no details as to which fields are involved.

                                                                    You need to think if you change the name of any field recently, but didn't update the scripts associated with it.

                                                                    After you solve this issue try again.

                                                                    • 31. Re: Calculation
                                                                      lvp1920 Level 1

                                                                      I corrected the problem and no error message is coming up, however, it still wont automate correctly.

                                                                      • 32. Re: Calculation
                                                                        try67 MVP & Adobe Community Professional

                                                                        Can you share the new version?

                                                                        • 33. Re: Calculation
                                                                          lvp1920 Level 1

                                                                          I shared it with you. Thanks so much

                                                                          • 34. Re: Calculation
                                                                            try67 MVP & Adobe Community Professional

                                                                            Why did you change the value of the owner variable to the combined value of the three fields?

                                                                             

                                                                            I think I might have misunderstood you earlier... When you asked to apply it to Market2 did you mean that you want to add the value of Market2 to that of Market1, or that it should be separately applied to the Market2 and Owner2 fields?

                                                                            • 35. Re: Calculation
                                                                              lvp1920 Level 1

                                                                              Its hard to explain.

                                                                               

                                                                              Scenario 1:

                                                                              If "H" is chosen in RealProp1 (which is the owner column) and the amount is $100.00 in Market1, then $100.00 should automatically be shown in "Husband 1" under summary of values.  If "W" is chosen for RealProp2 and the amount is $100.00 for Market2, then $100.00 should automatically be shown in "Wife 1" under summary of values. and for the last one, say "W" is chosen for RealProp3 and the amount is $50.00, then that amount would be added to the $100.00 that is already in "Wife 1" for a total of $150.00 in "Wife 1".

                                                                               

                                                                               

                                                                              Scenario 2:

                                                                              If "H" is chosen for RealProp1 and the amount is $100.00 in Market1, then it should automatically be shown in "Husband 1" under summary of values.  then, if "H" is chosen again for RealProp2 and another $100.00 is in Market2, then that would be added to "Husband 1" under summary of values. and again, if "H" is chosen for RealProp3 for another value of $100.00 in Market3, then that would be added to "Husband 1" and the total amount for "Husband 1" would be $300.00

                                                                               

                                                                               

                                                                                 Does that make more sense?

                                                                              • 36. Re: Calculation
                                                                                try67 MVP & Adobe Community Professional

                                                                                This is getting a bit complicated... I believe you have the basic code necessary to achieve it, and you can do some more research online to finish it. Or you can hire someone to write this code for you.