12 Replies Latest reply on Dec 3, 2017 12:18 PM by try67

    Calculate numbers in comments

    marcusss79

      Is it possible to calculate numbers that is added to a documents using comments?

      Like if i for instance add two comments to a document with the numbers 5 and 10. I would like the total value 15 presented in some way.

       

      I need this function to be able to make a time estime on how much time is needed to rewrite sections in a larger document.

        • 1. Re: Calculate numbers in comments
          try67 MVP & Adobe Community Professional

          It's possible, but not so simple. Why not use form fields?

          Also, where do you want the result to appear?

          • 2. Re: Calculate numbers in comments
            marcusss79 Level 1

            Thanks for the reply!

            In my field of work i often send out large documents for shared review.

            When i get them back they can contain hundreds of comments. Everything from small errors to big errors is covered in these reiviews.

            So i would like to add a reply to each comment with info on how many hours is needed to fix each issue in the comments.

             

            I am open for other suggestions if i can handle this in any other way.

            • 3. Re: Calculate numbers in comments
              Msedknowings Level 1

              Wow.  I must be asking the wrong question.  This question seems like the same question I asked, but I have no suggestions.  Perhaps I can piggyback on this one.  If this is possible for form fields to recognize comments and make a calculation from those comments, can you help me understand how this is done?  PLEASE.

              • 4. Re: Calculate numbers in comments
                try67 MVP & Adobe Community Professional

                So you want to then add up the numbers in your replies and show them in a field, for example?

                • 5. Re: Calculate numbers in comments
                  try67 MVP & Adobe Community Professional

                  As I wrote, this is not simple. Based on what do you want to recognize which comments to add up? Where do you want to display the result?

                  • 6. Re: Calculate numbers in comments
                    try67 MVP & Adobe Community Professional

                    One of the issues with doing it using a field (which is pretty much the only way I can think of) is that adding a new comment won't cause the calculation to update, which means you'll need to add a button to do it, which kind of defeats the point. You can just as well have the button display the result in an alert window.

                    • 7. Re: Calculate numbers in comments
                      try67 MVP & Adobe Community Professional

                      I've written this code to sum the values of all comments by a specific author (you can set the name on line #7) and display it in an alert. This could can be used from the Mouse Up event of a button field, for example:

                       

                      var total = 0;
                      this.syncAnnotScan();
                      var annots = this.getAnnots();
                      if (annots!=null) {
                          for (var i in annots) {
                              var annot = annots[i];
                              if (annot.author=="Me") {
                                  var v = annot.contents;
                                  if (v!=null && v!="" && !isNaN(Number(v))) {
                                      total+=Number(v);
                                  }
                              }
                          }
                      }
                      app.alert("Total: " + total, 3);
                      

                       

                      If you want to apply the value to a text field replace the last line with something like this:

                       

                      this.getField("Total").value = total;
                      
                      1 person found this helpful
                      • 8. Re: Calculate numbers in comments
                        Msedknowings Level 1

                        I am basically looking at the same situation.  I have very large files that I created a summary form report for.  I have added this one page summary to the top of all of my files.  Much of the info is autofill, but I am seeking a way for the form to target text in a comment that matches one of the options on the form and simply mark it with a check stating that this information was found within that file.  This is for the purposes of medical records and marking compliant information present or not. I'm hoping a javascript can do within the checkbox field.

                        • 9. Re: Calculate numbers in comments
                          try67 MVP & Adobe Community Professional

                          Sorry, this it too vague. I'll need to see the actual file to say for sure if it's possible or not.

                          You can contact me at try6767 at gmail.com to discuss it further.

                          • 10. Re: Calculate numbers in comments
                            Msedknowings Level 1

                            I will do this.  Thanks a million try67.  And thanks a million to you marcusss79 for asking your question and getting attention to the subject I was seeking.  My apologies for any deterrence this may have caused from your questions.  Enjoy the holidays. :-)

                            • 11. Re: Calculate numbers in comments
                              marcusss79 Level 1

                              Thank you so much try67! Wow this is exactly what i was hoping for. I have just one minor comment: is it possible to add a word or symbol that needs to be added to the "value comment" in order for the script to compute the value? For instance "#4" or "hours 4". This would be good to separate the "value comments" from any "real" comment that might also include digits.

                              • 12. Re: Calculate numbers in comments
                                try67 MVP & Adobe Community Professional

                                The code above will not add any numbers it finds in any comment, only those comments that contain only a number.

                                It is possible to have it only process things like "hours 4" (why not "4 hours", by the way?), but that would make it more complicated.

                                I think that the code above should be enough, especially since it's limited to only comments made by a specific author.