5 Replies Latest reply on Oct 10, 2016 9:11 AM by adga201222

    Check if Blank-> Don't print

    adga201222

      I have a time sheet form that I've copied 20 times. Only one field in the forms is different - the Name. Each name's form field is labeled "Name1", "Name2" etc. I had to create extra pages so that whoever is creating these sheets in the future will be able to add names when necessary, but these fields are blank for now. I don't want these extra pages to print and I'd rather not force the person printing the time sheets to have to check how many to print every time. Is there a way to check if a 'numbered set' of form fields is blank and set them to not print? This form field also happens to be the first field on each page if that helps. I have included an image of the sheet below. Thanks!

       

      Timesheet_Page_20.jpg

        • 1. Re: Check if Blank-> Don't print
          try67 MVP & Adobe Community Professional

          Yes, it can be done using a custom-made script, but it can only be used if the file is printed from a button that you add to it. It will not work if the user uses the built-in Print command of the application.

          1 person found this helpful
          • 2. Re: Check if Blank-> Don't print
            adga201222 Level 1

            Thank you for answering so quickly! Since it can be done, the only thing I can't find is how to do "not print."  I'm somewhat new to JavaScript, but my plan is to do something like this...

             

            var name1 = this.getField('Name1').valueAsString;
            var name2 = this.getField('Name2').valueAsString; //etc.
            
            var arr = [name1, name2,] //etc.
            
            var pp = this.getPrintParams();
            pp.interactive = pp.constants.interactionLevel.silent;
            pp.printRange = function() {
                 for(var i = 0; i < arr.length; i++) {
                      if arr[i] == "" {
                           //don't print
                      } else {
                           this.print
            };}
            

             

            Or would this be better?

             

            pp.printRange = function() {
                 for(var i = 0; i < arr.length; i++) {
                      if arr[i] != "" {
                           this.print
            };}
            

             

            I don't think the second would work without an else statement, but I'm unsure; I've never tried and it sounds like including an else is usually better. If the first would be better, I still need to figure out what the 'don't print' would be.

             

            Also, if anyone has any suggestions on how to make my code better, that would also be appreciated. I'm still learning, so I would appreciate some pointers.

            • 3. Re: Check if Blank-> Don't print
              Bernd Alheit Adobe Community Professional & MVP

              Both codes will not work.

              • 4. Re: Check if Blank-> Don't print
                try67 MVP & Adobe Community Professional

                You had the right idea, but your code was not quite correct. This version should work better:

                 

                var arr = ['Name1', 'Name2']; //etc. 
                
                var range = [];
                for (var i in arr) {
                    var f = this.getField(arr[i]);
                    if (f.valueAsString!="") {
                        range.push([f.page, f.page]);
                    }
                }
                
                if (range.length>0) {
                    var pp = this.getPrintParams();
                    pp.printRange = range;
                    this.print(pp);
                }
                
                • 5. Re: Check if Blank-> Don't print
                  adga201222 Level 1

                  The code works like a charm!! Thanks for the help!