Jump to content

Graphic rule executed ONLY if multiple fields are empty


KatJones

Recommended Posts

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.

for PTI Example.pdf

Link to comment
Share on other sites

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. :)

Link to comment
Share on other sites

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.

 

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.

 

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.

 

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.
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 =)

Link to comment
Share on other sites

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:

if (FIELD 2 == "") return Resource(YOUR RESOURCE);
else return NullResource();

For graphic frame #2, the code would be:

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. :)

Link to comment
Share on other sites

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:

 

if (Field("field2") == "")
return Resource("MYRESOURCE");
else return NullResource();

Link to comment
Share on other sites

Oops, I see where my previous solution will cause a problem. Let's change our logic to this:

// 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:

if (counter == 1) return RESOURCE;

with:

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. ;)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

example.zip

Edited by esmith
Link to comment
Share on other sites

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.

PTI.zip

Link to comment
Share on other sites

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".

 

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.

Link to comment
Share on other sites

I took your example, which works beautiful and wonderfully and does EXACTLY what I need it to do for mine, but when I copied and pasted to my layout and just switched out the field names and resource names it works... but...

 

The variable fields show duplicated on the preview. It will show the field(s) a large space/gap and then repeat those fields but they are tabbed over, then it will show the resource.

 

I noticed in your text frame you had custom tabs set up, but I didn't think that would have anything to do with the variable fields showing up twice even tho I don't have in the my text frame twice

Link to comment
Share on other sites

I think we are almost there! Your code seems to work with setup :D:D:D... however there seems to be a huge space in between the variable fields and the image when it shifts. When it gets to all 10 fields being populated the image runs off the page because of the huge gap.

 

The image itself doesn't have as much white space that the preview is showing.

Link to comment
Share on other sites

  • 1 month later...

I have a variable text field that has either 2 or 3 horizontal lines of text. They are divided vertically by a green graphic image. When there are only 2 lines of text, I need a portion of the green line covered up. I created a white box graphic and added it to the resources. Then I wrote this script:

 

if (Field("Direct") == "", Field("Cell") == "") return Resource("Resource1");

else return NullResource();

 

If both "Direct" and "Cell" are empty fields, the white box appears, which is what I want. If "Cell" exists, then the white box goes away, also what I want. But if "Direct" exists, the white box appears, which I do not want.

 

I thought it might be something simple, like add a line like this:

if (Field("Direct") !="") return NullResource();

 

but it doesn't work. I do not know JavaScript so I am confused.

Link to comment
Share on other sites

I have a variable text field that has either 2 or 3 horizontal lines of text. They are divided vertically by a green graphic image. When there are only 2 lines of text, I need a portion of the green line covered up. I created a white box graphic and added it to the resources. Then I wrote this script:

 

 

 

If both "Direct" and "Cell" are empty fields, the white box appears, which is what I want. If "Cell" exists, then the white box goes away, also what I want. But if "Direct" exists, the white box appears, which I do not want.

 

I thought it might be something simple, like add a line like this:

 

 

but it doesn't work. I do not know JavaScript so I am confused.

What do you think the comma (in red) is doing here?

if (Field("Direct") == ""[color=Red],[/color] Field("Cell") == "") return Resource("Resource1");
else return NullResource();

If you want to say "OR", then use the Logical OR Operator (||), like so:

if (Field("Direct") == ""[color=Red] [color=SeaGreen]||[/color][/color] Field("Cell") == "") return Resource("Resource1");
else return NullResource();

Or you could flip the logic, like so:

if (Field("Direct") != "" && Field("Cell") != "")
   return NullResource();
//else
return Resource("Resource1");

Which can be reduced to:

if (Field("Direct")" && Field("Cell"))
   return NullResource();
//else
return Resource("Resource1");

Or even:

return  (Field("Direct") && Field("Cell")) ? NullResource() : Resource("Resource1");

Link to comment
Share on other sites

hmm... still not working.

 

same problem with this:

if (Field("Direct") == "") return Resource("Resource1");

else if

(Field("Cell") == "") return Resource("Resource1");

else return NullResource();

 

If you look at the screenshots, it will show you a little more about what I am doing. I need the white box when only 2 numbers appear, but no white box when 3 numbers appear.

2-number-whitebox-yes.png.6adc68de8d4f956a4814ea7a98d0fbe6.png

3-number-whitebox-no.png.8c405d92f7b3a94819d6467448f8d9ce.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...