Hi Nicola,

Several issues here.

First, when you say, "when I preview in FusionPro both pages are being
used," do you mean you're using the Preview functionality?  If so,
that's always going to show you all of the pages.  You have to do an
actual composition to see the effects of page usage.

Regarding the code itself, the best way to figure out what's going on in
a case like this is to put some debugging code into the rule.  So I
would start out by adding some calls to the Print function, like so:

  if (Field("DepartmentName") != "" && Field("DepartmentNameCont") != ""

      && Field("AssociatedDeptName") != "" && sum1 == "8")
  { 
    Print("Activating page 2");
    FusionPro.Composition.SetBodyPageUsage("PG1", false);
    FusionPro.Composition.SetBodyPageUsage("PG2", true);
  }

  if (Field("DepartmentName") != "" && Field("DepartmentNameCont") != ""

      && Field("AssociatedDeptName") != "" && sum1 <= "7")
  {
    Print("Activating page 1");
    FusionPro.Composition.SetBodyPageUsage("PG1", true);
    FusionPro.Composition.SetBodyPageUsage("PG2", false);
  }

Then you can compose again and look in the log (.msg) file to see
exactly what's happening.  Once you get everything working, you can
remove or comment out the Print calls if you want.

Now, what you'll probably see is that for some records, you're
generating both of these messages, or more likely, neither.  The problem
is that you have two different "if" statements, which are not
necessarily mutually exclusive.  For instance, with the logic you have,
if the "DepartmentName" field is empty, both conditions are false, and
you don't execute either statement block, so page usage is unaffected.

If you really always want to do one thing or the other, you should just
use an "else" statement, like so:

  if (Field("DepartmentName") != "" && Field("DepartmentNameCont") != ""

      && Field("AssociatedDeptName") != "" && sum1 == "8")
  { 
    Print("Activating page 2");
    FusionPro.Composition.SetBodyPageUsage("PG1", false);
    FusionPro.Composition.SetBodyPageUsage("PG2", true);
  }
  else
  {
    Print("Activating page 1");
    FusionPro.Composition.SetBodyPageUsage("PG1", true);
    FusionPro.Composition.SetBodyPageUsage("PG2", false);
  }

Of course, you'll have to specify the right criteria in the "if"
statement.  What is supposed to happen if the "DepartmentName" field is
empty?

Also, remember that for page usage, you don't need to specify the usage
of each page for each record.  The pages will revert to the settings
defined in the Page Usage dialog at the beginning of each record.  So
you should either mark all the pages as Unused in the dialog, and only
activate the ones you want in the rule, or mark them all as Used in the
dialog and only deactivate the ones you don't want in the rule.  For
instance:

  // Pages PG1 and PG2 set to Unused in the dialog.
  if (Field("DepartmentName") != "" && Field("DepartmentNameCont") != ""

      && Field("AssociatedDeptName") != "" && sum1 == "8")
  { 
    Print("Activating page 2");
    FusionPro.Composition.SetBodyPageUsage("PG2", true);
  }
  else
  {
    Print("Activating page 1");
    FusionPro.Composition.SetBodyPageUsage("PG1", true);
  }

Of course, if/else logic like this can be simplified in several ways.
One way would be like so:

  var usePage2 = (Field("DepartmentName") != "" &&
      Field("DepartmentNameCont") != "" &&
      Field("AssociatedDeptName") != "" && sum1 == "8");
  var PageName = usePage2 ? "PG2" : "PG1";
  Print("Activating page: " + PageName);
  FusionPro.Composition.SetBodyPageUsage(PageName, true);  

Now, regarding how to determine the number of fields in use, yes, there
are more efficient ways to do that.  For instance:

  function NonEmptyFields()
  {
   var count = 0;

   for (var i = 0; i < arguments.length; i++)
   {
     try
     {
       if (Field(arguments[i]))
         count++;
     }
     catch (e)
     {
       Print(e);
     }
   }

   return count;
  }

  var FieldCount = NonEmptyFields("Name",
        "Title1", "Title2", "Phone",
        "Phone2", "Phone3", "Email", "WebAddress");

  // Pages PG1 and PG2 set to Unused in the dialog.
  var PageName = (FieldCount > 7) ? "PG2" : "PG1";
  Print("Activating page: " + PageName);
  FusionPro.Composition.SetBodyPageUsage(PageName, true);

You can easily modify the logic to add or remove fields from the list
you're counting.  Let me know if that works.

Dan


+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
FusionPro 5.0 Now Available!


Variable text on a curve and soft drop-shadows for variable text


LIMITED TIME upgrade offer of $299 per license for current customers:
http://fusionpro.printable.com/store/upgrade

New licenses available for $599 each at:
http://fusionpro.printable.com/store/

All FusionPro 5.0 customers to receive FusionPro 5.1 with
Adobe Acrobat 8 and InDesign CS3 support when released for FREE.
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
--
Users of FusionPro Desktop have unlimited free email support. Contact Printable 
Support at [EMAIL PROTECTED]
--
View FusionPro Knowledge Base, FusionPro Samples at
www.printable.com/vdp/desktop.htm

--
You are currently subscribed to fusionpro as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
--


--
Note:  All e-mail sent to or from this address will be received or otherwise 
recorded by the e-mail recipients of this forum. It is subject to archival, 
monitoring or review by, and/or disclosure to someone other than the recipient. 
Our privacy policy is posted on www.printplanet.com
--

Reply via email to