5 Replies Latest reply on Jan 6, 2011 9:30 AM by 19Ramon75

    Count fillColor fields?

    19Ramon75

      Is there a way to count fields with a specific fillColor?

       

      I have fields that set the fill color to yellow when a specific combination is selected in 2 separate fields.  Now I just need to count the number of times the fillColor = color.yellow is present in the fields.  I've been playing around with the following script that works to count text in fields:

       

      // array of field names to check

      var aFields = new Array("Field1", "Field2", "Field3", "Field4", "Field5");

      var count = 0; // variable to store count of non-empty fields

      for (i = 0; i < aFields.length; i++) {

      if (this.getField(aFields[i]).fillColor = color.yellow) count++

      } // end loop

      event.value = count;

       

      However, this fills each of the fields listed in the array to yellow.

       

      Any suggestions?


      Thanks

        • 1. Re: Count fillColor fields?
          try67 MVP & Adobe Community Professional

          First of all, the comparison operator is == , not = (which is the assignment

          operator, and why the color changes when you run this).

          However, since the color property is actually a special array, you need to

          use its equal() method to correctly compare two colors.

           

          So change your if statement to this:

           

          if (this.getField(aFields[i]).fillColor.equal(color.yellow)) count++

          1 person found this helpful
          • 2. Re: Count fillColor fields?
            19Ramon75 Level 1

            Changed it but it still didn't work.  Maybe there is an error in how I am using the fillColor in the fields I'm trying to count.  Below is the actual script I am using.  Are there any errors?

             

            var a = this.getField("E#2 LvP");
            var b = this.getField("E#2 Item Price");
            if ((a.value == " ") | (b.value <= "5000"))
            event.value = "";
            event.target.fillColor = color.white;
            if ((b.value > "5000") & (a.value =="Yes"))
            event.value = "ATTACH APPROPRIATE DOCUMENTATION";
            event.target.textColor = color.red;
            event.target.fillColor = color.white;
            if ((b.value > "5000") & (a.value =="No"))
            event.target.fillColor = color.yellow;

             

             

            Thanks

            • 3. Re: Count fillColor fields?
              try67 MVP & Adobe Community Professional

              I don't see where you're comparing the colors. Also, after each if-statement

              you need to place that code that should be executed between curly brackets.

              Otherwise, only the first line will be conditional. Like so:

               

              if (condition1) {

              // code dependant on condition1

              // more code dependant on condition1

              }

               

              if (condition2) {

              // code dependant on condition2

              // more code dependant on condition2

              // some more code dependant on condition2

              }

               

              etc.

              1 person found this helpful
              • 4. Re: Count fillColor fields?
                gkaiseril MVP & Adobe Community Professional

                Since the "fillColor" property returns an array, you will need to either compare each element of the array to the expected color array or convert the array to a string and compare the produced string value to a string that represents the color.

                 

                // test CMYK color array

                if (this.getField('Text.0').fillColor.join(',') == "CMYK,0,0,1,0") {

                // count yellow field

                }

                // test RGB color array

                if (this.getField('Text.0').fillColor.join(',') == "RGB,1,1,0") {

                // count yellow field

                }

                 

                Note. Colors can be represented by various different values. For example, the following color values can be used to set a field as "Yellow"

                 

                color.yellow

                ["RGB",1,1,0]

                ['CMYK',0,0,1,0]

                 

                But the test for the color is very different.

                 

                Try the following script for an example:

                 

                function TestYellow(sField) {
                var sMsg = "Not yellow";
                // test CMYK color array
                if (this.getField(sField).fillColor.join(",") == "CMYK,0,0,1,0") {
                sMsg = "CMYK yellow";
                }
                // test RGB color array
                if (this.getField(sField).fillColor.join(",") == "RGB,1,1,0") {
                sMsg = "RGB yellow";
                }
                return sMsg;
                }

                this.getField("Field1").fillColor = color.yellow;
                app.alert(TestYellow("Field1"));
                this.getField("Field1").fillColor = ["RGB",1,1,0];
                app.alert(TestYellow("Field1"));
                this.getField("Field1").fillColor = ["CMYK",0,1,0,0];
                app.alert(TestYellow("Field1"));
                this.getField("Field1").fillColor = ["RGB",0,1,0];
                app.alert(TestYellow("Field1"));

                • 5. Re: Count fillColor fields?
                  19Ramon75 Level 1

                  Both of you were very helpful on this matter.

                   

                  Putting - if (this.getField(aFields[i]).fillColor.join(',') == "CMYK,0,0,1,0") count++ into my script resulted in the count of each yellow highlighted field.

                   

                  I did follow the suggested action of putting each fillColor condition in brackets { }

                   

                  Thank You