Generating Repeated Sequence Number Through Code

Recommended Posts

Hello,

I have a weird project. We get it once a year and in years past it's basically been garbage-in-garbage-out. Customer sends us 100's of PDFs of donation receipts, each corresponding to a certain customer of theirs and broken out by number of pages each donator receives.

So, for example, I might have an ABC Company folder, which contains "ABC YE - 1 page 1-2024-01-18T19_44_57 FINAL.pdf" and "ABC YE - 2 page 2024-01-18T19_44_57 FINAL.pdf".

If 1 page PDF has 200 pages, there are 200 records to mail.
If 2 page has 200 pages, there are 100 records to mail.
If 3 page has 90 pages, there are 30 records to mail.
etc.

So we used to drop these PDFs into a hot folder to impose them 2out on 12x18, they would print 4/0, and the handwork department would have to manually parse out the pages to stuff into the full-window envelopes.

For everyone's sanity this year, we'd like to put some identifying information on each page. Right now I have "Version# - [1,2,3]PG - SEQ#" in the upper right corner of each page.

The "data" file I've been given is a spreadsheet that has 1 line per customer, and then columns for 1 Page count, 2 Page count, 3 Page count, and 4+ Page count

The trick here is I've been asked to sequence by group, not by page. So if it's a 2pager, they want pages 1-2 to have seq 1, pages 3-4 to have seq 2, pages 5-6 to have seq 3, etc.
Same for the 3pagers, pages 1 - 3 = seq 1, 4- 6 = seq 2, 7 - 9 = seq 3, etc.

Sequencing the 1 pagers was easy. I did:

```FusionPro.Composition.repeatRecordCount = Field("1 Page count");

======================================================================

return FormatNumber("0000", FusionPro.Composition.outputRecordNumber);```

Sequencing the 2 pagers was trickier, because I am super rusty with Javascript. But I ended up doing the following:

```FusionPro.Composition.repeatRecordCount = Field("2 Page count") * 2;

======================================================================

var seqNum;

if(FusionPro.Composition.repeatRecordNumber%2 != 0)
var seqNum = (FusionPro.Composition.repeatRecordNumber + 1)/ 2;
else
var seqNum = FusionPro.Composition.repeatRecordNumber / 2;

return FormatNumber("0000",seqNum);```

Not sure if it's the "correct" way to do it, but it's working.

Now here's where I'm stuck. I cannot for the life of me figure out how to sequence the 3pagers or the 4+pagers.

I assume there's some way I can utilize loops, but as stated, I am super rusty with JS.

If you've read this far and this all makes sense to you, I'd really appreciate some guidance.
(I know as soon as I see it I'm going to smack my forehead and go "oh duh!" 😏)

If you've read this far and you cannot help, well, hello and happy New Year at least 🙂

Share on other sites

i don't completely understand.  What happens if you have non-zero numbers in, say, both the "2 page count" and "3 page count" fields?  You can only set repeatRecordCount once per record.

I might need to see a minimal example of the job, or at least a mockup of the output, to understand better.

At any rate, it seems to me like the "sequence number" is simply the FusionPro.Composition.repeatRecordNumber.  The first three pages would be repeat 1, and the next three pages would be repeat 2, and so on, right?

Share on other sites

1 hour ago, Dan Korn said:

i don't completely understand.  What happens if you have non-zero numbers in, say, both the "2 page count" and "3 page count" fields?  You can only set repeatRecordCount once per record.

I might need to see a minimal example of the job, or at least a mockup of the output, to understand better.

Hi Dan,

I have separate templates for 1page, 2page, and 3page, and the rules in those templates refer to the corresponding field (1 Page count, 2 Page count, and 3 Page count)

I've attached the output if you'd like to see, as well as my 1page template and 2page template.

1 hour ago, Dan Korn said:

At any rate, it seems to me like the "sequence number" is simply the FusionPro.Composition.repeatRecordNumber.  The first three pages would be repeat 1, and the next three pages would be repeat 2, and so on, right?

I thought so too, but when I use FormatNumber("0000",FusionPro.Composition.repeatRecordNumber) instead I get sequence numbers 1 - 50 on my PDF instead of 1,1,2,2,3,3,4,4,...,25,25 which is my goal. See attached TEST pdf. When the recipient is only getting 1 page in their envelope 1 - 50 is what I want, but if they are getting 2 pages or 3 pages I want the pages that go together to have the same sequence number. I hope that makes sense.

I know it's kind of crazy, and if I cannot find a solution soon I may make myself a new data file that has repeating record numbers in a column instead. I'm just trying to touch the data as little as possible while also trying to get it out the door ASAP (because of course everything needs to mail by 1/31 and the project fell into my lap yesterday).

Share on other sites

52 minutes ago, hsprinkle said:

See attached TEST pdf.

Wow, thanks for attaching all of that, but it's a lot.  Can you throw me a bone and point me to which of the attachments contains that PDF?  Maybe say say which ones are the outputs and which are the templates?

Also, where exactly am I looking for the sequence number?

Share on other sites

2 hours ago, Dan Korn said:

Wow, thanks for attaching all of that, but it's a lot.  Can you throw me a bone and point me to which of the attachments contains that PDF?  Maybe say say which ones are the outputs and which are the templates?

Also, where exactly am I looking for the sequence number?

Sorry, the FP.zips are the collects of the templates

.xlsx file is the data file I'm working off of

art.zip is two of the art files from the customer, just to see how the PDFs are coming in to me initially

240035 Receipt - bridge_builders - 1 page - 246 records file 1.pdf is print output file for the 1page data

240035 Receipt - bridge_builders - 2 page - 25 records file 1.pdf is the output for the 2page data, where you can see how I am trying to repeat the sequence number

240035 Receipt - bridge_builders - 2 page TEST - 25 records file 1.pdf is what happens when I use FusionPro.Composition.repeatRecordNumber as you suggested on the 2page template, where I'm getting seq 1 - 50 instead of 1,1,2,2,3,3,...,25,25 which is my goal

Sequence number is in the top right corner of the 8.5x11 page, it is imposed 2-out on 12x18

I appreciate you trying to take a look at it, sorry I didn't respond sooner, I thought I'd get an email alert if there were new replies.

If it is more complicated code-wise than me just not knowing JS very well, I am okay figuring out a way to manually sequence the 3 and 4+ pagers as I need, there are not a lot of them.

Share on other sites

Okay, I see.  You're multiplying the "X page count" field by X to get the repeat count.  So the rule should be:

```var seqNum = Math.ceil(FusionPro.Composition.repeatRecordNumber / pageCount);
return FormatNumber("0000", seqNum);```

Where "pageCount" is the "X": 1 for your 1-pager, 2 for your 2-pager, etc. This should generalize for any repeat count.

Also, I don't think you really need separate templates for 1 page, 2 page, 3 page, etc.  You could just have a global variable for that page count, that you could, say, read from a secondary data file in OnJobStart, like so:

```var PageCountFile = new ExternalDataFileEx("PageCount.txt");
pageCount = PageCountFile.GetFieldValue(0, 0);```

Then in OnRecordStart:

`FusionPro.Composition.repeatRecordCount = Field(pageCount + " Page count") * pageCount;`

Then all you need to do is put a different number in that PageCount.txt file (or whatever you want to call it) and run again.

You might also want to do this in the JavaScript Globals just to make rule validation easier:

`var pageCount = 1;`

Or, forget about reading the pageCount from the external data file in OnJobStart, and just change its value in the JavaScript Globals directly.

Of course, this can be generalized further; you could repeat to handle all the page counts in a single composition with just a little more math.

Share on other sites

By the way, Math.ceil isn't magic; it literally just means "round up to the next highest integer (whole number)."  So in the 3-page case, 1/3, 2/3, and 3/3 round up to 1; 4/3, 5/3, and 6/3 round up to 2; 7/3, 8/3, and 9/3 round up to 3, etc.  That's exactly the algorithm you describe here:

6 hours ago, hsprinkle said:

So if it's a 2pager, they want pages 1-2 to have seq 1, pages 3-4 to have seq 2, pages 5-6 to have seq 3, etc.
Same for the 3pagers, pages 1 - 3 = seq 1, 4- 6 = seq 2, 7 - 9 = seq 3, etc.

Share on other sites

Mail.ceil is exactly what I needed, thank you Dan!!!

And thank you for the explanation of what it does, that makes perfect sense to me!

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.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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

×
×

• FusionPro.com

• MarcomCentral
• Store

×
• Create New...