Jump to content

I want to repeat a record


Recommended Posts

Is there some javascript that will allow me to repeat a record x number of times (like 50, 100 or 200). That value can be either in a field or fixed in the java script.

What we are doing is printing half a dozen business cards on a sheet, but we need to have 100 copies of some cards, and 50 of another.

 

Thanks,

 

David

Link to comment
Share on other sites

fp_example.pdf contains 3 pages -- a job ticket and 2 "body" pages. The output.pdf shows the result (I think) you are trying to achieve. You should be able to compose the former file as is (currently uses Futura Bold) to reproduce the output.

 

The OnRecordStart callback rule set each record to repeat 50 times and disables the job ticket on the 2nd thru 50th iterations while adding a 51st record which adds the job ticket only.

 

The OnJobStart rule is only used in the example to bypass a data file for demonstration purposes.

fp_example.pdf

output.pdf

Link to comment
Share on other sites

I need to output a file in which the first page is a job ticket and has information about the job, the following pages repeat the job, say 50 times.

That's pretty easy; just do this in your OnRecordStart rule:

FusionPro.Composition.repeatRecordCount = 50;
// FusionPro.Composition.repeatRecordCount = Int(Field("repeat")); // or this
FusionPro.Composition.SetBodyPageUsage(1, FusionPro.Composition.repeatRecordNumber == 1);

Then this is followed by the job ticket again.

Can this be done?

That's a bit more complicated. One way to do this is to add an extra record at the end of the job, then suppress all the other pages except the first one; something like this:

FusionPro.Composition.repeatRecordCount = 51; // adding one here
// FusionPro.Composition.repeatRecordCount = Int(Field("repeat")) + 1; // or this
FusionPro.Composition.SetBodyPageUsage(1, FusionPro.Composition.repeatRecordNumber == 1);

if (FusionPro.Composition.repeatRecordNumber == FusionPro.Composition.repeatRecordCount)
{
   // Last record; output just the first page.
   FusionPro.Composition.SetBodyPageUsage(1, true);
   for (var p = 2; p < 100; p++)
   {
       try
       {
           // this throws an error if the name number is invalid
           FusionPro.Composition.SetBodyPageUsage(p, false);
       }
       catch (e)
       {
           // no more pages to set usage for
           break;
       }
   }
}

Link to comment
Share on other sites

I see Eric beat me to the punch. His solution is perfectly fine. Although mine takes advantage of the fact that, as long you're in FusionPro 8.0 or newer, you don't actually need to name the pages; you can just use page numbers in the calls to FusionPro.Composition.SetBodyPageUsage(). So mine is more generic, since it should work for any job, regardless of the number of pages or their names (or lack of names).
Link to comment
Share on other sites

Thanks, guys

 

I actually was just coming back to say that I did something that worked (and shocked myself!).

 

FusionPro.Composition.SetBodyPageUsage("Ticket" , false);

if (FieldChanged("Column"))

{

FusionPro.Composition.SetBodyPageUsage("Ticket" , true);

}

FusionPro.Composition.repeatRecordCount = Int(Field("Qty"));

Link to comment
Share on other sites

I'm having a hard time visualizing what it is you're trying to accomplish with the imposition. How many business cards are you trying to get up on a sheet? 20? 5 rows and 4 columns? If that's the case, I'd think you'd just set your stack height to be pieces/columns (i.e 51/4=13. 51 because of the ticket at the start of the set of 50) in the imposition definition. It might help if you could post an example of how you'd like the output to look.

 

But you should consider that when you impose the job, you need to make sure that each record produces the same number of pages. By that I mean, when you turn on the ticket page, you need to turn off the business card page. I'd modify your code to look like this:

 

FusionPro.Composition.repeatRecordCount = Int(Field("Qty")) + 1; // add one for the ticket
FusionPro.Composition.SetBodyPageUsage("Ticket" , FusionPro.Composition.repeatRecordNumber == 1);
FusionPro.Composition.SetBodyPageUsage(2, FusionPro.Composition.repeatRecordNumber != 1);

Link to comment
Share on other sites

Well,

I have spent quite a few hours today trying to do this myself. You can tell me I've reached my limit on free meals (though I used FP for 6 years in another job and never asked a question)

For each record, I want to output a beginning ticket, x copies of the job, and an end ticket. The following code gives me the right count, but it places the two tickets at the beginning and then the repeated page. In Page Usage they are also in the order that I want to output.

 

FusionPro.Composition.repeatRecordCount = Int(Field("Qty")) + 2;

FusionPro.Composition.SetBodyPageUsage("Ticket", FusionPro.Composition.repeatRecordNumber == 1);

FusionPro.Composition.SetBodyPageUsage("PDF", FusionPro.Composition.repeatRecordNumber != 1);

FusionPro.Composition.SetBodyPageUsage("Ticket2", FusionPro.Composition.repeatRecordNumber == 1);

Link to comment
Share on other sites

For each record, I want to output a beginning ticket, x copies of the job, and an end ticket. The following code gives me the right count, but it places the two tickets at the beginning and then the repeated page. In Page Usage they are also in the order that I want to output.

repeatRecordCount tells FP how many times to run each record.

repeatRecordNumber tells FP which iteration of the repetition of the current record it is on.

setBodyPageUsage takes two arguments: the page name (or number) and true/false (whether to activate page or not).

 

In Ste's code, the 2nd argument is an equation that yields either true or false so in your modification:

FusionPro.Composition.SetBodyPageUsage("Ticket", FusionPro.Composition.repeatRecordNumber == 1);

activates "Ticket" on the first iteration (repeatRecordNumber is equal to 1),

 

FusionPro.Composition.SetBodyPageUsage("PDF", FusionPro.Composition.repeatRecordNumber != 1);

activates "PDF" for everything BUT the first iteration (repeatRecordNumber is not equal to 1), and

 

FusionPro.Composition.SetBodyPageUsage("Ticket2", FusionPro.Composition.repeatRecordNumber == 1);

activates "Ticket2" for the first iteration (repeatRecordNumber is equal to 1).

 

Make sense?

 

In order to generate each record with 1 "Ticket" followed by X "PDFs" followed by 1 "Ticket2", you would need your second arguments to yield:

  1. repeatRecordNumber equals 1
  2. repeatRecordNumber greater than 1 AND less than X+2 (repeatRecordCount)
  3. repeatRecordNumber equals X=2 (repeatRecordCount)

Are you still with me?

 

To do this, I would revise your code like this:

var finalTicket = Int(Field("Qty")) + 2;
FusionPro.Composition.repeatRecordCount = finalTicket;
FusionPro.Composition.SetBodyPageUsage("Ticket", FusionPro.Composition.repeatRecordNumber == 1);
FusionPro.Composition.SetBodyPageUsage("PDF", FusionPro.Composition.repeatRecordNumber > 1 && FusionPro.Composition.repeatRecordNumber < finalTicket);
FusionPro.Composition.SetBodyPageUsage("Ticket2", FusionPro.Composition.repeatRecordNumber == finalTicket);

I opted to assign "X+2" to a variable so that the following code would be a bit cleaner. The double ampersands means "AND" which means both equations must test true to activate page.

 

Now that you understand what the code is doing, you may not need that free meal (but if you do, there are always others willing to help). :)

Edited by esmith
Link to comment
Share on other sites

Eric,

 

Thank you very much. I particularly appreciate that you have defined the FusionPro.Composition functions; I have been searching for that information for a while.

 

BTW - I spent a week down there about 7 years ago when we were getting trained in Fusion Pro web. Funny thing, we didn't get a free lunch then, we went (usually) to the little grocery on the corner.

 

David

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