10 Replies Latest reply on Jun 29, 2017 7:53 AM by Karl Heinz Kremer

    Help with positive and  or negative data put into a field

    steft66579364

      Hi,

       

      Can someone please help me , I have 10 fields which are populated with measured data.

      The data can be positive or negative, but not greater than -10 or +10

      If the data being measured is put into any of the fields, is less than or =  -10  / + 10 then I want to populate another field with "pass"

      but if the data being put into any of the fields is greater than -10 /+10 then I want to populate the other field with "fail"

      This is measured data,microns so can be positive or negative.

       

      Many thanks

        • 1. Re: Help with positive and  or negative data put into a field
          Bernd Alheit Adobe Community Professional & MVP

          steft66579364  wrote

          ...

          The data can be positive or negative, but not greater than -10 or +10

          ...

          Can you explain this? Every positive number is greater than -10.

          • 2. Re: Help with positive and  or negative data put into a field
            Karl Heinz Kremer Adobe Community Professional

            You can use something like the following script as the custom calculation script for your pass/fail field:

             

            // get the data from the form field
            var d = this.getField("Data1").value;
            
            if (d == "") {
                event.value = "";
            }
            else if (Math.abs(d) > 10) {
                event.value = "fail";
            }
            else if (Math.abs(d) <= 10) {
                event.value = "pass";
            }
            
            • 3. Re: Help with positive and  or negative data put into a field
              gkaiseril MVP & Adobe Community Professional

              Do you mean the data needs to be within  +/- 10 of a given measurement or the value needs to be between -10 and +10 .

               

              The following script can handle either case when the correct values for the stand and the range are entered.

               

              // get the data from the form field ;

              var d = this.getField("Measurement").valueAsString;  // test field valueAsString;

              if(d == "")

              {

              // no entry for test

              event.value = "";

              } else {

              // report if test result within allowed range;

              var nStandard = 15; // required standard;

              var nRange = 10; // acceptible variance from standard;

              // compute difference from a standard;

              var nDiff = Math.abs(nStandard - Number(d))

              event.value = (nDiff > nStandard) ? "Fail", : "Pass";

              }

               

              One could even write a custom function to indicate a pass or fail for the result when compared to a standard and a range for acceptance.

               

              Such a function could be:

               

               

              function Results(nStandard, nRange, nTestValue)
              {
              // function to return logical true or false if test value not within the range for the standard value;
              return Math.abs(nStandard - nTestValue) <= nRange;
              } // end Results function;

               

               

              And the custom calculation for the individual result field could then be:


              // get the data from the form field ;
              var d = this.getField("Measurement").valueAsString;  // test field valueAsString;
              if(d == "")
              {
              // no entry for test
              event.value = "";
              } else {
              // report if test result within allowed range;
              var nStandard = 15; // required standard;
              var nRange = 10; // acceptible variance from standard;
              // compute difference from a standard;
              event.value = Results(nStandard, nRange, d) ? "Pass" : "Fail";
              }

              • 4. Re: Help with positive and  or negative data put into a field
                steft66579364 Level 1

                Hello gkaiseril,

                 

                really appreciate your response, forgive me if I am wrong but your answer applies to one field

                I have 8 fields that all need to be between -10 micron and 10 micron.

                How could I write the above the 8 different fields

                See below

                thank you

                 

                Stef

                • 5. Re: Help with positive and  or negative data put into a field
                  steft66579364 Level 1

                  Hello, Karl Heinz Kremer

                   

                  I tried your script for 8 fields

                  var h = this.getField("ValueH").value;

                  var g = this.getField("ValueG").value;

                  var f = this.getField("ValueF").value;

                  var e = this.getField("ValueE").value;

                  var d = this.getField("ValueD").value;

                  var b = this.getField("ValueB").value;

                  var a = this.getField("ValueA").value;

                  if(h==""&&g==""&&f==""&&e==""&&d==""&&c==""&&b==""&&a=="") {

                  event.value="";

                  }

                  else if (Math.abs(h,g,f,e,d,c,b,a) >  10){

                  event.value "Fail";

                  }

                  else if (Math.abs(h,g,f,e,d,c,b,a) < = 10) {

                  event.value = "Pass";

                   

                  But I get an error on line 12 ; missing statement

                   

                  any help please

                   

                  Stef

                  • 6. Re: Help with positive and  or negative data put into a field
                    Test Screen Name Most Valuable Participant

                    You can't replace abs(one thing) with abs(list,of,many,things). You need separate abs for each value. You have to connect them with && (and) or || (or); think about which one is right.

                    • 7. Re: Help with positive and  or negative data put into a field
                      Karl Heinz Kremer Adobe Community Professional

                      You would have to copy the script I provided to all eight Pass/Fail fields and then adjust the field name that is checked.

                      • 8. Re: Help with positive and  or negative data put into a field
                        steft66579364 Level 1

                        Thank you I have altered my scripted

                        • 9. Re: Help with positive and  or negative data put into a field
                          steft66579364 Level 1

                          Hello Karl,

                           

                          Thank you , I got it working.

                          Much appreciated

                           

                          Stef

                          • 10. Re: Help with positive and  or negative data put into a field
                            Karl Heinz Kremer Adobe Community Professional

                            After re-reading your question, I realized that you don't have either pass/fail fields, but only one for the eight data fields. This means that you have to use a different kind of script from what I first proposed. You do have everything you need in my first script, all you ned to add is a few lines of standard Javascript (this has nothing to do with Acrobat's implementation) to create a loop over all fields and then bail out when one does not fit the "pass" criteria. However, based on the syntax errors in your script, it looks like your JavaScript skills could use some improvements. I would strongly suggest that you learn how to program in JavaScript when you are using JavaScript in a project. Take a look here for some guidance about how to approach learning to program in JavaScript: Learning to Program JavaScript for Adobe Acrobat - KHKonsulting LLC

                             

                            You cannot just copy and paste your way through a problem and end up with something that both works and is maintainable. You will need to know enough about what you find online to be able to fix minor typos (nobody here is a perfect typer, and most of the code that I type is not even validated by Acrobat's JavaScript parser), or to adapt a solution to your specific needs. This can only be done when you know enough about the programming language to spot potential problems - or fix them when the parser points one out to you - or to make small adjustments like adding a loop around a few lines of code.

                             

                            Based on what I know about your requirements, the following script might work for your form:

                             

                            var dataFields = ["ValueA", "ValueB", "ValueC", "ValueD", "ValueE", "ValueF", "ValueG", "ValueH"];
                            var newValue = "pass";
                            
                            for (var f in dataFields) {
                              var d = this.getField(dataFields[f]).value;
                            
                              if (d == "" || Math.abs(d) > 10) {
                              newValue = "fail";
                              break;
                              }
                            }
                            
                            event.value = newValue;