Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library > Graphic Rules

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old July 17th, 2013, 10:40 AM
KatJones KatJones is offline
Junior Community Member
 
Join Date: Sep 2011
Location: Atlanta, GA
Posts: 22
Default Graphic rule executed ONLY if multiple fields are empty

I need help writing a rule that I am sure is fairly easy, however I can't wrap my head around exactly how to write it.

I have 1(one) graphic that I need to fluctuate 9 times in position on the page based on the database.

I have 9 fields that all have different data in them per record. Sometimes all 9 fields for one record are populated, sometimes only 1 or 2 fields is populated.

I would need the rule for my graphic position 1 to say: If field "field 1" and "field 2" and "Field 3", Etc... is blank return my graphic. Else return nothing at all.

and the same thing for my graphic position 2, where the rule would say: If field "field 2" and "field 3" and "Field 4", Etc... is blank return my graphic. Else return nothing at all. Each subsequent graphic rule would be one less field to consider because in theory that one will be populated.

Everything I have tried resulted in my graphic showing up in all the positions even though I excluded one field for each subsequent rule I wrote.

I have included an example of what I am trying to achieve. See how the bottom text (Which I made a graphic-due to font issues) moves with the variable text-that I blurred out for security purposes.
Attached Files
File Type: pdf for PTI Example.pdf (2.65 MB, 24 views)
__________________
FP 9.1.0 Producer, Windows Server 2008 R2, Acrobat 10.1.9
Reply With Quote
  #2  
Old July 17th, 2013, 11:36 AM
esmith's Avatar
esmith esmith is offline
Senior Contributor
 
Join Date: Oct 2008
Location: Charlotte, NC
Posts: 870
Default Re: Graphic rule executed ONLY if multiple fields are empty

What are the graphics that you are returning? Do you have separate graphics that each contain steps 1-10 (in graphic format) with the difference being the amount of space between steps 2 and 3 based on how many of 9 fields contain a value (presumably with up to 9 clients per record)?

In your example, the graphic in position 2 contains an image IF field 1 is empty but the other 8 fields contain a value; the graphic in position 3 contains an image IF fields 1 and 2 are empty; etc. What happens if fields 3 and 5 are empty? Are you trying to place graphics based on specific fields being null or specific numbers of fields being null?

I'm thinking you would have just one graphic frame that can contain any of your 9 graphic resources and then return the specific one needed based on the values (or lack thereof) of the 9 fields in your data. I'd be happy to take a stab at a solution once I am certain I understand your ultimate goal and how to handle all the possible scenarios.
__________________
Eric Smith
Content Developer
Classic
FP 9.3.6, MAC OSX 10.9.4, Acrobat 11.0.09
Reply With Quote
  #3  
Old July 17th, 2013, 01:00 PM
KatJones KatJones is offline
Junior Community Member
 
Join Date: Sep 2011
Location: Atlanta, GA
Posts: 22
Default Re: Graphic rule executed ONLY if multiple fields are empty

Quote:
Originally Posted by esmith View Post
What are the graphics that you are returning?
It is the #3 thru #10 Paragraphs, an image of text due to font issues. Otherwise this would be a text rule issue I'm having.

Quote:
Originally Posted by esmith View Post
Do you have separate graphics that each contain steps 1-10 (in graphic format) with the difference being the amount of space between steps 2 and 3 based on how many of 9 fields contain a value (presumably with up to 9 clients per record)?
No. it is just one graphic that I need to move around. I assumed that could make 9 different graphic rules with the graphic being suppressed if it conditions of that particular rule didn't apply.

Quote:
Originally Posted by esmith View Post
In your example, the graphic in position 2 contains an image IF field 1 is empty but the other 8 fields contain a value; the graphic in position 3 contains an image IF fields 1 and 2 are empty; etc.
Field 1 will never be empty. However 2-10 may be. So if Field 1 is populated I would need the "text" Image to be close to the variable data, IF Field 1 and 2 are populated and 3-10 are empty then the same image would need to be in another position as not to block the populated data, OR show up where the first graphic box is. So forth for if field 1, 2, and 3 is populated but 4-10 aren't.

Quote:
Originally Posted by esmith View Post
What happens if fields 3 and 5 are empty?
It won't jump around like that. The fields would be in consecutive order of how it populates.
Quote:
Originally Posted by esmith View Post
Are you trying to place graphics based on specific fields being null or specific numbers of fields being null?
Specific fields

I hope my answers help you help me =)
__________________
FP 9.1.0 Producer, Windows Server 2008 R2, Acrobat 10.1.9
Reply With Quote
  #4  
Old July 17th, 2013, 01:20 PM
esmith's Avatar
esmith esmith is offline
Senior Contributor
 
Join Date: Oct 2008
Location: Charlotte, NC
Posts: 870
Default Re: Graphic rule executed ONLY if multiple fields are empty

In that case, the easiest solution (if not the most elegant) would be to have 9 unique rules applied to 9 unique graphic frames. The rule for graphic frame #1 would be:
Code:
if (FIELD 2 == "") return Resource(YOUR RESOURCE);
else return NullResource();
For graphic frame #2, the code would be:
Code:
if (FIELD 3 == "") return Resource(YOUR RESOURCE);
else return NullResource();
and so on. Essentially each frame's content is determined by whether that "position"/"field" contains a value -- it is assumed that if a particular field has no value, all the following fields will also be blank so there is no need to test the value in every field for every frame.

Hopefully that makes sense and matches your intent.
__________________
Eric Smith
Content Developer
Classic
FP 9.3.6, MAC OSX 10.9.4, Acrobat 11.0.09
Reply With Quote
  #5  
Old July 17th, 2013, 02:43 PM
KatJones KatJones is offline
Junior Community Member
 
Join Date: Sep 2011
Location: Atlanta, GA
Posts: 22
Default Re: Graphic rule executed ONLY if multiple fields are empty

That didn't appear to work. All 9 graphics still showed up, overlapping one another, in the record where Field 1 was only one populated while 2-10 was blank, and if field 1&2 was populated but 3-10 was blank, and so on...

Also when I inserted your code I got the syntax error message that missing ) in line 1 after the argument. So I tried this and didn't get a error but still it didn't work:

Code:
if (Field("field2") == "")
return Resource("MYRESOURCE");
else return NullResource();
__________________
FP 9.1.0 Producer, Windows Server 2008 R2, Acrobat 10.1.9
Reply With Quote
  #6  
Old July 17th, 2013, 04:08 PM
esmith's Avatar
esmith esmith is offline
Senior Contributor
 
Join Date: Oct 2008
Location: Charlotte, NC
Posts: 870
Default Re: Graphic rule executed ONLY if multiple fields are empty

Oops, I see where my previous solution will cause a problem. Let's change our logic to this:
Code:
// replace "ALL CAPS" placeholder text with your field names/resource
var allFields = [FIELD1,FIELD2,FIELD3,FIELD4,FIELD5,FIELD6,FIELD7,FIELD8,FIELD9];
var counter = 0;
for (var i=0; i<allFields.length; i++) {
   if (allFields[i] != "") counter++;
}
// change next line for each of nine duplicate rules
if (counter == 1) return RESOURCE;
else return NullResource();
The code I posted would be for graphic frame #1. In graphic frame #2, you would place a duplicate rule where you change:
Code:
if (counter == 1) return RESOURCE;
with:
Code:
if (counter == 2) return RESOURCE;
and so on for each frame's rule.

The effect (hopefully) is that frame 1 (with rule #1 assigned) will only return the common resource if counter=1 (i.e. only one of the nine fields contains a value). All the other frames' rules (i.e. graphic frame #4/rule #4) will return nothing. Likewise, if counter=4 (i.e. 4 of the 9 fields contain a value), graphic frame #4 (with rule #4 assigned) will return the common resource while all other frames' rules return nothing.

Note that an alternative method would be to have one graphic frame and 9 resources, each with varying amounts of white space included at the top for the proper offset. In this scenario you would only need one rule and one frame (on bottom layer), returning the correct resource based on the value of counter.

Even better, in FusionPro 8.x, you could have a single graphic frame with a single resource and change the offsets of the frame's Y-position based on the value of counter.
__________________
Eric Smith
Content Developer
Classic
FP 9.3.6, MAC OSX 10.9.4, Acrobat 11.0.09
Reply With Quote
  #7  
Old July 18th, 2013, 11:22 AM
KatJones KatJones is offline
Junior Community Member
 
Join Date: Sep 2011
Location: Atlanta, GA
Posts: 22
Default Re: Graphic rule executed ONLY if multiple fields are empty

I was so hopeful that code was going to work... but it didn't

It doesn't switch, only shows the resource for if fields 2-10 are empty, but when Field 1 and 2 is populated and 3-10 are empty and so on, the other graphic frames doesn't work.
__________________
FP 9.1.0 Producer, Windows Server 2008 R2, Acrobat 10.1.9
Reply With Quote
Old July 18th, 2013, 12:01 PM
esmith
This message has been deleted by esmith. Reason: better solution offered
  #8  
Old July 18th, 2013, 12:36 PM
esmith's Avatar
esmith esmith is offline
Senior Contributor
 
Join Date: Oct 2008
Location: Charlotte, NC
Posts: 870
Default Re: Graphic rule executed ONLY if multiple fields are empty

I've attached a sample job of how I would set this up. I don't know how you are formatting your 1-9 lines of data in "step 2" so it may make more sense to use a table there or set up custom tabs, but the example shows how to include the final "8 steps" as a graphic regardless of number of populated fields.
Attached Files
File Type: zip example.zip (4.47 MB, 16 views)
__________________
Eric Smith
Content Developer
Classic
FP 9.3.6, MAC OSX 10.9.4, Acrobat 11.0.09

Last edited by esmith; July 18th, 2013 at 12:39 PM..
Reply With Quote
  #9  
Old July 18th, 2013, 12:55 PM
KatJones KatJones is offline
Junior Community Member
 
Join Date: Sep 2011
Location: Atlanta, GA
Posts: 22
Default Re: Graphic rule executed ONLY if multiple fields are empty

Yes I did duplicate the rule and change the count. I have attached a mock version of the actual piece with the graphic positions already in place.

The fields I was referencing in this thread are called "clientid", "clientid2", etc...

"ClientID" will always be populated, but as you can see that ClientID2 thru ClientID10 sometimes won't. So when 2-10 aren't populated the graphic frame that I have named as "Position 1" should show.

And when all 10 ClientID fields are populated only the graphic frame I have named as "Position 9" should show.
Attached Files
File Type: zip PTI.zip (69.4 KB, 8 views)
__________________
FP 9.1.0 Producer, Windows Server 2008 R2, Acrobat 10.1.9
Reply With Quote
  #10  
Old July 18th, 2013, 02:30 PM
mcmahand mcmahand is offline
Junior Community Member
 
Join Date: Oct 2010
Location: Charlotte, NC
Posts: 22
Default Re: Graphic rule executed ONLY if multiple fields are empty

Another way to you could do this is actually a text box, and that would only require 1 rule.

You can make one large text box roughly similar to the area covered by the 9 graphic boxes now. The text box may have to be slightly wider than your page (or crop off part of the right edge of the graphic resource). And you'll have to play with the position and height of the text box.

Create a text rule with code similar to below, and check to "Treat returned strings as tagged text".

Code:
var returnText = "";

var allFields = [Field("userid1"),Field("userid2"),Field("userid3"),Field("userid4"),Field("userid5"),Field("userid6"),Field("userid7"),Field("userid8"),Field("userid9"),Field("userid10")];
var counter = 0;
for (var i=0; i<allFields.length; i++) {
   if(allFields[i] != "")
    {
        returnText += "<P>";
    }
}

return returnText + "\<graphic resource=\"PTI Resource\" position=\"afterline\"\>";
This code is crude and just adds paragraph tags to push the inline graphic down the page. I'll leave it as another exercise to get the leading and line spacing just right.

Tidying up more, you could create a variable length table for the userids and include the graphic inline below it without needing the paragraph tags at all.
__________________
David McMahan
Document Composition Developer
Shutterfly
FP 10.0.26, Windows 8, Acrobat DC
Reply With Quote
Reply

Tags
graphic, javascript, rules

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 06:46 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.