3 Replies Latest reply on Feb 13, 2014 10:58 AM by BSisson

    How do I grab the left 50 char of a field.

    BSisson

      I am trying to make "pretty" reports that wrap neatly.

       

      The Report consists of GeneralNotes.1..GeneralNotes.50

       

      I loop through all of my conditions, and when a section needs to have its ExportData move to the report I get the handles (getField) for the current line and the current line on the report.

       

      I copy one to the other, increment the line on the report and continue....

       

      This works fine....

       

      HOWEVER, if the lines are LONG, they get trunkated, shrunk in font, or something else.

       

      If the lines are long, I want to split the line into two pieces, and process them

       

      f is the current incomming report line  (field)to be processed

      s is the current line (field) on the report page

       

            if f.value.length > 70

               { var firstpart  = this.f.slice(0,70);       //this -SHOULD- be the first 70 char

                var leftover   = this.f.slice(71);          //this -SHOULD- be the remainder.

                s.value = firstpart.value;

                 position = position +1;

                 s = this.getField("GeneralNotes."+position);

                 f.value = leftover.value;

                }

      //else

               {s.value = f.value;                                              //stuff Export value into currnet Summary field

             position = position +1;

              }

      //continue with the rest of the loop stuff...

       

      The Real code works very well and builds a nice pretty report so long as f.value is less than 70 char long.

       

      I get no errors, -BUT- both lines on the report come out as "undefined" when the line is too long.

       

      Putting in some console.println statements the "slice" widget doesn't seem to be supported...or I am using it wrong....

       

      So the logic works.  The .length part works

       

      but the "slice" portion doesn't seem to work.

       

      The "slice" documentation I used came from w3school.com   http://www.w3schools.com/jsref/jsref_slice_string.asp

       

      Since this doesn't seem to be supported, is there another function or field widget I can use to split a 'field.value' into two pieces?

       

      Or can someone tell me where my syntax is wrong?

        • 1. Re: How do I grab the left 50 char of a field.
          George_Johnson MVP & Adobe Community Professional

          It seems to me it should be more like:

           

              if (f.valueAsString.length > 70) {

                  var firstpart = f.valueAsString.slice(0,70);       //this -SHOULD- be the first 70 char

                  var leftover = f.valueAsString.slice(71);          //this -SHOULD- be the remainder.

                  s.value = firstpart;

                  position += 1;

                  s = this.getField("GeneralNotes."+ position);

                  s.value = leftover;

              } else {

                  s.value = f.valueAsString;                              //stuff Export value into currnet Summary field

                  position += 1;

              }

          1 person found this helpful
          • 2. Re: How do I grab the left 50 char of a field.
            gkaiseril MVP & Adobe Community Professional

            Maybe there is some other issue with your code.

             

            Variables do not have a value property. They only have a value.

             

            Have you tried adding some console.println statements to see what your code is doing and at what line it is failing?

             

            if (f.value.length > 70) {

                    console.show();

                     console.clear();

                     console.println("length: " + f.value.length);

                     var firstpart  = this.f.slice(0,70);       //this -SHOULD- be the first 70 char

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

                      var leftover   = this.f.slice(71);          //this -SHOULD- be the remainder.

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

                       console.println("set field value to " + firstpart.value);

                      s.value = firstpart.value;

                       position = position +1;

                       s = this.getField("GeneralNotes."+position);

                       f.value = leftover.value;

                      } else {

                      s.value = f.value;                                              //stuff Export value into currnet Summary field

                       position = position +1;

                    }

            //continue with the rest of the loop stuff...

            1 person found this helpful
            • 3. Re: How do I grab the left 50 char of a field.
              BSisson Level 1

              Aha... the 'valueAsString' did it...

               

              There was one more "position = position +1" needed as it was over writing the 2nd line with the next entry, but that was my error.

               

              Now I have a summary form that builds its self conditionally from  750+ fields, and writs a nice summary that will nicely format response that are anywhere from 1-2 lines long.

               

              .