10 Replies Latest reply on Aug 25, 2016 2:11 PM by gkaiseril

    Return blank if zero

    Monteigo99 Level 1

      Hello,

       

      I have a form with 5 fields that are drop down boxes. There are 4 choices: Blank (default), Y, N, N/A. I have two fields that produce a calculation. One returns '# of #' and the other produces a % of Y's.

      In the default state of blank, the calculations are '0 of 0' and '0%'. The problem is that, unfortunately, some providers will want a printed hardcopy to fill out and the fields have these zero's in them.

       

      How can I make the field so blank? I have tried several variations to no avail.

       

      1st script '0 of 0':

      var totalY = 0; 

      var total = 0; 

      for (var i=1; i<=5; i++) { 

          var f = this.getField("JJCRDropdown"+i); 

          if (f.valueAsString=="Y") { 

              totalY++; 

              total++; 

          } else if (f.valueAsString=="N") { 

              total++; 

          } 

      if (total==0) event.value = ""; 

      else event.value = totalY / total;

       

       

      2nd script '0%':

      var totalY = 0; 

      var total = 0; 

      for (var i=1; i<=5; i++) { 

          var f = this.getField("JJCRDropdown"+i); 

          if (f.valueAsString=="Y") { 

              totalY++; 

              total++; 

          } else if (f.valueAsString=="N") { 

              total++; 

          } 

      if (total==0) event.value = ""; 

      else event.value = totalY / total;

        • 1. Re: Return blank if zero
          try67 MVP & Adobe Community Professional

          Change:

          if (total==0) event.value = "";

          To:

          if (totalY==0 || total==0) event.value = "";

          • 2. Re: Return blank if zero
            Monteigo99 Level 1

            Thank you once again Try67, it works for the '0 of 0' field but not the %

             

            Is there something else I have to do for that field. I know % outputs sort of screw some things up.

            • 3. Re: Return blank if zero
              gkaiseril MVP & Adobe Community Professional

              Have you looked at the "real" value of the field and not just the "formatted" displayed value?

               

              To see the actual value of the calculated field try:

               

              var totalY = 0;
              var total = 0;
              for (var i = 0; i < 6; i++) {
                  var f = this.getField("JJCRDropdown" + i);
                  if (f.valueAsString == "Y") {
                      totalY++;
                      total++;
                  } else if (f.valueAsString == "N") {
                      total++;
                  }
              }

              // display totals used in calculations;

              console.show();

              console.clear();

              console.println("totalY: " + totalY);

              console.println("total : " + total);

              console.println("toatlY / total : " + (totalY / total));

              // end display of values;
              if (total == 0)
              {
              event.value = "";
              }
              else{

              event.value = totalY / total;
              }

               

              You should see that the actual value of the field is a decimal value and not a "%". You need to set the format as needed by the value of the field. I do not think you want to use the "total" variable since if there is any "N" value you will have a none zero value for the "total".

               

              I would set the format for the field to "Custom" then use a custom format script area to set the format for the field using a script like:

               

              if(event.value  == "" )

              {

              AFNumber_Format(2, 0, 2, 0, "", false);

              }

              else{

              AFPercent_Format(2, 0, false);

              }

              • 4. Re: Return blank if zero
                Monteigo99 Level 1

                Ok, I have to study that one a bit.

                I had to adjust the event.values because once I plugged in the requested script, it would no longer recognize the totalNA script.

                Why can't I get ALL of these to function. I can only get 2 of the 4 to work at a time.

                 

                if (totalNA==5) event.value = "N/A";

                if (totalY==0 || total==0) event.value = "";

                if (total==0) event.value = totalY+ " of " + total;

                else event.value = totalY + " of " + total;

                • 5. Re: Return blank if zero
                  try67 MVP & Adobe Community Professional

                  Think about the logic of your statements.

                  The last two statements cover all possible scenarios (either total is 0 or it's not), so they make the first two statements moot.

                  • 6. Re: Return blank if zero
                    Monteigo99 Level 1

                    I get that, but this was what happened.

                    When I went from this:

                    if (totalNA==5) event.value = "N/A";

                    else event.value = totalY + " of " + total;

                     

                    To this:

                    if (totalNA==5) event.value = "N/A";

                    if (totalY==0 || total==0) event.value = "";

                    else event.value = totalY + " of " + total;

                     

                    the blank field worked but it negated the N/A.

                     

                    I think what would work is if I could say, but I can't find reference for this:

                    if (totalY==0 || total==0) AND (totalNA<5) event.value = "";

                    • 7. Re: Return blank if zero
                      gkaiseril MVP & Adobe Community Professional

                      Samples that others can review work much better than verbal descriptions.

                       

                      You also have to have to clearly describe your problem. Form your other posts, it appears you need to count all the "Yes", "No", and ".N/

                      A" responses. You are calculating the percentage of "Yes" response of the total of the "Yes" and "No" responses.

                       

                      Is it possible this method might work for you?

                       

                      See example

                       

                      I thought you wanted a result of "0" or "null" to appear as a null string without the percentage mark. Now it looks like you want that and some other value if the result is not zero or null.

                      • 8. Re: Return blank if zero
                        Monteigo99 Level 1

                        I have two fields that calculate from the same 5 drop downs. The % field calculates from the '0 of 0' field. I want to count the yes's and no's and have it populate, but I only want it to say N/A if ALL 5 drop downs are N/A.  If 1) <5 dropdowns are NA and the others are blank, I want both calc fields to be blank, 2) all drops are blank, then calc's are blank.

                        The scripts are different for each calc  field due to the percentage.


                        Did that make sense?

                         

                        My government securities would not allow the example link locations to be viewed.

                        • 9. Re: Return blank if zero
                          try67 MVP & Adobe Community Professional

                          I think what would work is if I could say, but I can't find reference for this:

                          if (totalY==0 || total==0) AND (totalNA<5) event.value = "";

                           

                          To do that use this code:

                           

                          if ((totalY==0 || total==0)) && (totalNA<5)) event.value = "";

                          • 10. Re: Return blank if zero
                            gkaiseril MVP & Adobe Community Professional

                            I would calculate the fields individually since it is just to complex to parse the numbers form field displaying "# of #".

                             

                            When all 5 fields have the "N/A" response, what do you want to display in percentage field?

                             

                            I have provided you an approach for blanking the percentage result when the percentage is zero.

                             

                            You can always provide an example form with just the fields needed for the calculations and the results of the calculations. That way you are not disclosing any .design, instructions,, country, or departmental information