Expand my Community achievements bar.

SOLVED

How to print only pages with field data

Avatar

Level 6

Hypothetical scenario:

Say I have a doc with 10 pages, and each page has 10 fields.  Of those 10 fields, I would to implement either solution when the document is printed:

1. A script that scan the first field on each page, if the value != null then, include that page in print operation, or

2. Script scans all fields on each page checking for the first field with data (among the 10 fields). If any of the 10 fields has data, then include that page to the print operation. I's image this would be some sort of loop script (for, while, etc)

I would love to get option #2 working, but would take #1 if it's easier to implement.

I sincerely thank whomever in advance for any advice, suggestions, and/or recommendations.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

Have a look at an example here: http://assure.ly/MzX1bK. This will satisfy option 2.

Hope that helps,

Niall

View solution in original post

12 Replies

Avatar

Correct answer by
Level 10

Hi,

Have a look at an example here: http://assure.ly/MzX1bK. This will satisfy option 2.

Hope that helps,

Niall

Avatar

Level 10

This is just to test out the code block.

// Hide the page

this.presence = "hidden";

// Call the function

AssureDynamics.CheckForNull(page1, page1);

Niall

Avatar

Level 6

Hi Niall,

Thank you sooo much for the quick reply and for providing the example. I'm in the process of testing and will report back soon.

Quick question... I follow 95% of what you are doing in the script/function, but I want to make sure that this will work in causes where there might be repeating subforms and new pages are automatically generated. Since you mentioned the script works recursively, then I presume it will. I only ask because I see we are placing the code block on every page on the prePrint event (i.e. page 1), but what happens if the repeating subform on page1 creates page1[1] and page1[2]? Again, I "believe" you have that scnario convered in your script, but will check. I truly hope this works!!!!

Thanks

Shaun

Avatar

Level 10

Hi Shaun,

Yes, this should still work as the overflow page is still just an instance of page1.

Good luck,

Niall

Avatar

Level 6

Thanks!

Ok, everything appeared to be working fine, but for some reason I'm was having pages print that had 100% null values...so I thought. It turned out to be because I had "default values" in certain fields (duh...lol). However, I believe one page was unexpectedly triggered by a subform instance script (i.e. this.rawValue = subForm.index + 1;)

Then I had an issue with the document changing the MasterPage designations when certain pages remained hidden. I believe this was because many of the pages simply had “Follow Previous” settings. My design has over 19 pages that use 6 different Master Pages.

So for instance, initially I had doc page 1 set to MasterPageA, then pages 2-5 were set to “Follow Previous. The page 6 was set to MasterPageB (landscape mode design), page 7 was set to “MasterPageA  --Top of Page”  and pages 8-10 set to “Follow Previous”.  Well, the problem I was having was if page 7 was null and remained hidden, pages 8-10 took on the landscape orientation of MasterPageB (page 6 setting) since pages 8-10 were set to “Follow Previous”. 

The way I had to overcome this was by setting each specific page to occur on “Top of Page” so that even if the main page setter was hidden (i.e. page 7), each page would point to the correct Master Page independently vs. “Following Previous”.

I hope that wasn’t confusing…

In either case, all appears to be working now.

THANK YOU SO MUCH AGAIN! You guys are awesome!

Avatar

Level 10

Hi Shaun,

Yes, default values and objects with script that set the rawValue, will satisfy the !== null and therefore will allow the page to be printed. To get around that you would need to name these objects specifically AND then amend the function to test for the object name. For example, name the fields, DONOTTESTtextfield1.

You would be moving away from a completely generic solution, but it could be done.

Your form structure is more complicated than the sample, but it should be workable.

Good luck,

Niall

Avatar

Level 6

Thanks, I follow.

Question...Not looking for you to spend any major time on this, but could something as simple as adding a variable and new modified Case to the function, work...for example:

var check = subFormA.textfield1.rawValue;

else if(currentElement.className === "field") { 

            // Check if object are null and specific field(s)ARE NOT null (known default values present)

            if (currentElement.ui.oneOfChild.className !== "checkButton" && currentElement.rawValue === null && check !== null) {

                pageReference.presence = "hidden"; 

                return;

                  }

So in the above instance, it will hide the page in cases were all fields are null except the ones with known defualt values.

Lastly, why is the "checkButton" used twice?

// Case 2 of 4

        // If the objects are fields we test to see if they have a value. If the field is not

        // null, then we show the parent object (page) again.

        else if(currentElement.className === "field") { 

            // Check if object is not null

            if (currentElement.ui.oneOfChild.className !== "checkButton" && currentElement.rawValue !== null) {

                pageReference.presence = "visible"; 

                return;

                  }

// Case 3 of 4 (note this is specifically within the className "field" section)

            // If the objects are checkboxes and are not

            // null, then we show the parent object (page) again.

            if (currentElement.ui.oneOfChild.className === "checkButton") { 

            // Check if object is not null

                if (currentElement.rawValue !== 0) {

                    pageReference.presence = "visible";

                    return;

                }

                  }

Avatar

Level 6

Naill, Disregard the first half of my previous request ...I realized after testing my theory it's much more complex than I imagined.

Avatar

Level 10

Hi Shaun,

There are a couple of things here, so I'll try and take them one at a time.

Do not process certain fields

For this I would have the start of the objects that you do not want processed, to have names that start with a set string. Like "DONOTTESTtextfield1". Then the else if statement becomes:

else if (currentElement.className === "field" && currentElement.name.substring(0,9) !== "DONOTTEST") {

Do you see that the script will then only fire on fields that do not start with "DONOTTEST"?

Checkbox

The checkbox is a field, BUT does not have a state when its .rawValue is null. Generally a checkbox is either 0 or 1, and therefore always has a value.

In the script above, Case 2 of 4 is testing fields that are not null, but explicitly not testing checkboxes. Then Case 3 of 4 is a specific case to test checkboxes on their own, because we are testing the checkbox field is not 0.

Make sense?

Also note that the first test is testing that the currentElement is NOT a checkbox:

currentElement.ui.oneOfChild.className !== "checkButton"

Whereas the second test is testing that the currentElement IS a checkbox:

currentElement.ui.oneOfChild.className === "checkButton"

Hope that helps,

Niall

Avatar

Level 10

Okay Shaun,

I have updated the example to deal with objects to be excluded. This is as outlined above. The updated example is available at the same link (http://assure.ly/MzX1bK).

Hope that helps,

Niall

Avatar

Level 6

Niall,

I've been testing this and I gotta tell you, this is pretty awesome.  I really appreciate you taking your time to help me. I know it probably helps that I have a general understating of scripting, but it goes without saying that your assistance and involvement was very instrumental in help me surpass my initial goal.

The only thing I question is what's the difference between using === and ==, or !== and !=.  I often just use == or !=, but I'm sure there's a deeper purpose.

Shaun

Avatar

Level 10

Glad you have it working Shaun!

As you know == and != are testing equality and inequality. These work very well when testing conditions, it can be useful to test for identity (===) or nonidentity (!==). These operators are testing that the two values are identical. This means that not only are you testing that the values are the same, but also the type (eg number, string, boolean).

For example, these two tests are the same:

if (this.rawValue != null || this.rawValue != "") {

if (this.rawValue !== null) {

You will find more detailed explanations online.

Hope that helps,

Niall