Jump to content

Supressing lines within a rule


Jeff Berry

Recommended Posts

I am having trouble figuring out how to suppress some lines within one of my rules. I have suppressed lines before but never within a rule. I would like the "Vice President" and "Third Member" lines to suppress if there isn't a name pulled from my external data source. Is that possible?

 

if (FusionPro.inValidation)
   Rule("OnJobStart");

outstr = "";
RepName1 = "";
Position1 = "";
RepName2 = "";
Position2 = "";
RepName3 = "";
Position3 = "";

for (i = 1; i <  XDF_CityContacts.recordCount+1; i++)
   {
   County = XDF_CityContacts.GetFieldValue(i, 0)
Position = XDF_CityContacts.GetFieldValue(i, 6)

       if (Field("County#") == County && Position == "President")

               {
                   RepName1 = XDF_CityContacts.GetFieldValue(i, 1);
                   Position1 = Position;

               }

       else if (Field("County#") == County && Position == "Vice President")
               {
                   RepName2 = XDF_CityContacts.GetFieldValue(i, 1);
                   Position2 = Position;

               }

       else if (Field("County#") == County && Position == "Third Member")
               {
                   RepName3 = XDF_CityContacts.GetFieldValue(i, 1);
                   Position3 = Position;

               }
       }


outstr = '<p findent="0" lindent="0" skipifempty="true"><f name="Arial"><b>'+RepName1+
'</b><i><p skipifempty="true" leading="125" leadbefore="0"><f name="Arial"><t>'+"President"+
'</i><p findent="0" lindent="0" skipifempty="true"  leadbefore="650" ><f name="Arial"><b>'+RepName2+
'</b><i><p skipifempty="true" leading="125"  leadbefore="0" ><f name="Arial"><t>'+"Vice President"+
'</i><p findent="0" lindent="0" skipifempty="true"  leadbefore="650" "><f name="Arial"><b>'+RepName3+
'</b><i><p skipifempty="true" leading="125" leadbefore="0"><f name="Arial"><t>'+"Third Member";

return outstr;

Link to comment
Share on other sites

Well, you're building up the text yourself in the rule, so just don't include the parts you don't want. I would just add the lines as you go, that is, as you find the data in the file, like so:

 

if (FusionPro.inValidation)
   Rule("OnJobStart");

var outstr = "";

for (var i = 1; i <= XDF_CityContacts.recordCount; i++)
{
   County = XDF_CityContacts.GetFieldValue(i, 0)
   Position = XDF_CityContacts.GetFieldValue(i, 6)

   if (Field("County#") == County && Position == "President")
   {
       outstr += '\n<p><f name="Arial"><b>'+
           XDF_CityContacts.GetFieldValue(i, 1)+'</b>'+
           '\n<p leading="125"><f name="Arial"><t><i>'+Position+'</i>';
   }
   else if (Field("County#") == County && Position == "Vice President")
   {
       outstr += '\n<p leadbefore="650"><f name="Arial"><b>'+
           XDF_CityContacts.GetFieldValue(i, 1)+'</b>'+
           '\n<p leading="125"><f name="Arial"><t><i>'+Position+'</i>';
   }
   else if (Field("County#") == County && Position == "Third Member")
   {
       outstr += '\n<p leadbefore="650"><f name="Arial"><b>'+
           XDF_CityContacts.GetFieldValue(i, 1)+'</b>'+
           '\n<p leading="125"><f name="Arial"><t><i>'+Position+'</i>';
   }
}

return outstr;

Note that I've removed some of the paragraph settings that don't do anything, such as first indent of zero, which is the default anyway, and also the "skipifempty" attribute, because you're adding text such as "President", so the paragraph is never going to be empty.

 

Actually, except for a slight difference in the "leadbefore" attribute, which you could easily compensate for in the text frame, the entire loop above reduces to this:

for (var i = 1; i <= XDF_CityContacts.recordCount; i++)
{
   County = XDF_CityContacts.GetFieldValue(i, 0)
   Position = XDF_CityContacts.GetFieldValue(i, 6)

   if (Field("County#") == County)
   {
       switch (Position)
       {
           case "President":
           case "Vice President":
           case "Third Member":
           {
               outstr += '\n<p leadbefore="650"><f name="Arial"><b>'+
                   XDF_CityContacts.GetFieldValue(i, 1)+'</b>'+
                   '\n<p leading="125"><f name="Arial"><t><i>'+Position+'</i>';
           }
       }
   }
}

And I'm not even sure you need the switch statement (but I don't have your data file or any of the rest of the job to know for sure).

 

However, having done all of that, you're still a bit limited here by having to all all the text formatting with tags. If you rework this logic a bit to inject variables into the composition instead, then you can use them in a text frame just like regular text fields in the WYSIWYG Variable Text Editor dialog, and not having to worry about the tagging at all. Just move this logic into OnRecordStart instead of the rule to have now:

 

for (var i = 1; i <= XDF_CityContacts.recordCount; i++)
{
   County = XDF_CityContacts.GetFieldValue(i, 0)
   Position = XDF_CityContacts.GetFieldValue(i, 6)

   if (Field("County#") == County && Position == "President")
   {
       FusionPro.Composition.AddVariable("RepName1", XDF_CityContacts.GetFieldValue(i, 1));
       FusionPro.Composition.AddVariable("Position1", Position);
   }
   else if (Field("County#") == County && Position == "Vice President")
   {
       FusionPro.Composition.AddVariable("RepName2", XDF_CityContacts.GetFieldValue(i, 1));
       FusionPro.Composition.AddVariable("Position2", Position);
   }
   else if (Field("County#") == County && Position == "Third Member")
   {
       FusionPro.Composition.AddVariable("RepName3", XDF_CityContacts.GetFieldValue(i, 1));
       FusionPro.Composition.AddVariable("Position3", Position);
   }
}
// nothing to return here

Then you can simply type the variables RepName1, Position1, etc., in to the Variable drop-down list in the Text Editor, and click Insert to use them in your text frames, and set the formatting in the GUI. You'll also be able to use the "Suppress if containing empty variables" setting in the Paragraph Formatting dialog.

Link to comment
Share on other sites

Thanks a ton for your help! It helped a lot to see the variety of ways to accomplish the task. My first project if FusionPro is pretty complex (at least I think so) so I'm still stumbling my way through. I hope to be an expert at this soon.

 

Thanks again!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...