2 Replies Latest reply on Jun 15, 2017 12:31 PM by garyw_308

    radio button group, average values from 1 - 5, done. I can even auto format a summary text field and highlight appropriate summary responses BUT, I have been given two caveats for the average summary. IF a 2 is present, the value will be 2. IF a 5 is pres

    garyw_308

      I have a functioning set of tools in an inspection document (Utility industry recertification)  that allows the user to select grades by question by section. There are  seventeen sections and various numbers of questions per section...

      Using a document level java script, I can create a summary average per section (separate calculation per section), highlight a checkbox in the section summary based on the average score that covers the requirements in that section, change colors to point out items for review.... So far, so good.

       

      I am now working on a baffling part, and that is the variable section scoring parameters with two overriding considerations in the section score that
      translates into the overall summary and follow on chart…I have tried various methods to extract the values of the radio buttons from an array looking for the  2 && 5 but so far, no joy.

      1. That no matter how the individual questions per section are scored (Exceeds, Satisfies, Partially Satisfies, Fails to Satisfy, N/A), if any one of the answers is ‘Fails to Satisfy Requirements’, then the section will be marked as “Key Attention Areas for Improvement”, and will show as a red bar on the summary chart.
      2. Second consideration is that if in any section that does NOT have a ‘Fails to Satisfy’, and has at least one Exceeds, will be marked as ‘Strong Performance’ and show a green bar on the summary chart.
      3. The other conditions where the scores by section do not have either an ‘Exceeds’, or ‘Fails’ will result in an averaging of the ‘Satisfies’ and ‘Partially Satisfies’. This will result in the bars being yellow (Generally Satisfactory) or blue(Satisfactory Performance) based on average score.

      Any question marked ‘N/A’ is not included in the average.

       

      I have this all working except for the #1 and #2 caveats above...

       

      How much broken code do you need to see?

        • 1. Re: radio button group, average values from 1 - 5, done. I can even auto format a summary text field and highlight appropriate summary responses BUT, I have been given two caveats for the average summary. IF a 2 is present, the value will be 2. IF a 5 is
          garyw_308 Level 1

          I am adding the following so you may see what is working and where. Restating my question at the bottom.

           

          // definition of document level functions;
          // filter callbacks used to select elements to keep in an array;
          
          function isNotNull(element) {                    // remove null values array;
            return String(element).length != 0;
            }
          
          function isNotNaN(element) {                   // remove NaN values from array;
             return element = !isNaN(element);
             }
          // end filter callbacks;
          
          function aAverage(aNumbers) {                 // average values in array;
          var nSum = 0;
          for(var i = 0; i < aNumbers.length; i++) {
              nSum +=Number(aNumbers[i]);
              }
          var nAverage = "";
          if(aNumbers.length > 0) {
              nAverage = nSum / aNumbers.length;
              }
          return nAverage;
          } // end aAverage function;
          
          function aFieldNames2aValues(aNames) {   // put the values of named fields into an array;
              var aValues = new Array();
              for(var i = 0; i < aNames.length; i++) {
          aValues.push(this.getField(aNames[i]).valueAsString);
              }
              return aValues;
          }
          
          function AverageFieldNames(aFieldNames) {
              var aValues = aFieldNames2aValues(aFieldNames);
              aValues = aValues.filter(isNotNull);     // remove null values;
              aValues = aValues.filter(isNotNaN);    // remove Not a Number values;
              return aAverage(aValues);                 // compute average;
          }                                                             // end aAverageFieldNames function;
          // end function definitions;
          

           

           

           

          At the form level, insert this into the custom calculation script field for the section summary average

          // custom calculation script;
          var aFieldNames = ["Q7", "Q8", "Q9", "Q10", "Q11", "Q12", "Q13", "Q14", "Q15", "Q16"];
          event.value = AverageFieldNames(aFieldNames);
          // end of custom calculation script; 
          

           

           

          In the custom format script of the same text box that is calculating the section average, insert the following. This will make the correct ‘BOX’ highlight appropriately.

          The below begins “BoxA2” because this was pulled from the second section. First section would be BoxA1.

           

          if((String(event.value) == "") || (event.value == 0))
          {// No Entry
          this.getField("BoxA2").value = "Off";
          this.getField("BoxB2").value = "Off";
          this.getField("BoxC2").value = "Off";
          this.getField("BoxD2").value = "Off";
          this.getField("BoxE2").value = "1";
          }
          else if(event.value >= 4.5)
          {
          this.getField("BoxA2").value = "5";
          this.getField("BoxB2").value = "Off";
          this.getField("BoxC2").value = "Off";
          this.getField("BoxD2").value = "Off";
          this.getField("BoxE2").value = "Off";
          }
          else if(event.value >= 3.5)
          {
          this.getField("BoxA2").value = "Off";
          this.getField("BoxB2").value = "4";
          this.getField("BoxC2").value = "Off";
          this.getField("BoxD2").value = "Off";
          this.getField("BoxE2").value = "Off";
          }
          else if(event.value >= 2.5)
          {
          this.getField("BoxA2").value = "Off";
          this.getField("BoxB2").value = "Off";
          this.getField("BoxC2").value = "3";
          this.getField("BoxD2").value = "Off";
          this.getField("BoxE2").value = "Off";
          }
          else if(event.value >= 2)
          {
          this.getField("BoxA2").value = "Off";
          this.getField("BoxB2").value = "Off";
          this.getField("BoxC2").value = "Off";
          this.getField("BoxD2").value = "2";
          this.getField("BoxE2").value = "Off";
          }
          else
          {
          this.getField("BoxA2").value = "Off";
          this.getField("BoxB2").value = "Off";
          this.getField("BoxC2").value = "Off";
          this.getField("BoxD2").value = "Off";
          this.getField("BoxE2").value = "1";
          }
          
          
          // set target field color to default values;
          if((String(event.value) == "") || (event.value == 0))
          {
          event.target.fillColor = color.transparent;
          }
          else if(event.value >= 4.5)
          {
          event.target.fillColor = color.green;
          }
          else if(event.value >= 3.5)
          {
          event.target.fillColor = color.blue;
          }
          else if(event.value >= 2.5)
          {
          event.target.fillColor = color.yellow;
          }
          else if(event.value >= 2)
          {
          event.target.fillColor = color.red;
          }
          else
          {
          event.target.fillColor = color.transparent;
          } 
          

           

          The last bit above formats the fillcolor of the text box that is holding the average calculation. This one box is getting a lot done.

           

          I am curious about one bit above. At the document level, I have adjusted the color.blue to be,

          fillColor.blue = ["RGB", 0, 1, 1]; or light blue. I also tried using “RGB”, 124,218,252
          

          and

          I also changed the font color.blue = ["RGB", 0, 1, 1];  BUT while the text colors are resulting as a nice light blue, the fill colors are remaining dark blue… obscures the black numbers in that field. Right now, this is a curiosity and the least of my issues.

           

          Any suggestions on how to set the event.value to 2 if a 2 is present in any radio button group or to set the event.value to 5 if a 5 is present and no 2 is present in any radio button group?

          • 2. Re: radio button group, average values from 1 - 5, done. I can even auto format a summary text field and highlight appropriate summary responses BUT, I have been given two caveats for the average summary. IF a 2 is present, the value will be 2. IF a 5 is
            garyw_308 Level 1

            So far, I have fixed the color question. Has to be declared locally

            1. // set target field color to default values;
            2. color.blue = ["RGB",0,0.75,1];
            3. if((String(event.value) == "") || (event.value == 0)) 
            4. {

            then call for color.blue as the fill color as above and it worked out. Document level declaration was not picked up.