View Single Post
Old May 4th, 2020, 04:12 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,504
Default Re: Help with complex composition

Okay, thanks for posting the template. I still had to guess a bit as to what you want the output to be (a picture can be worth a thousand words), but the attached template should do what I think you want.

There's a lot going on here, but a few basic notes:

First, some of the code was in the wrong place. Some properties of the FusionPro.Composition object can be set only in certain Callback/Event rules; for instance, the composeAllRecords property can be set only in OnJobStart, and repeatRecordCount can be set only in OnRecordStart.

Conversely, some functions can't be called in certain rules. In particular, the Field function can't be called in either the JavaScript Globals nor in the OnJobStart function, as you're not actually in the context of a particular record (which has a particular value for the data field).

Also, you usually either want to set startRecordNumber and endRecordNumber OR set repeatRecordCount, but not both. Usually, it's easier to set set FusionPro.Composition.repeatRecordCount (in OnRecordStart) and access FusionPro.Composition.repeatRecordNumber to do something different for each repeat; that's what I've done here.

I've also made use of the FusionPro.Composition.AddVariable function to "inject" certain text variables, rather than writing a bunch of separate yet related rules for each one. This allows all the code to be centralized into a single rule, which is OnRecordStart. This one rule can "drive" what happens in each output record and file. I think that keeping all the logic in one place like this makes it easier to understand and maintain, but your mileage may vary.

You'll see some math in the rule, including use of the % (modulus) operator, to calculate things like which ticket number we're on within the current book, as well as some plain old division (with the / operator), and some functions such as Int and Math.ceil to round the results of such divisions to the next-lowest or next-highest integer value.

Note also that there aren't really any "loops" in the rule per se (though I did leave some commented-out code to debug the setting of all those other variables for the various numbers like which ticket and book we're on at each point in the repeat). The main repetition is triggered by setting FusionPro.Composition.repeatRecordCount, and by accessing FusionPro.Composition.repeatRecordNumber to vary the output per repeat. Also, I think the code as written will handle the case where StartNumber is something other than 1, but of course you will want to craft some data to test that particular case.

More thoughts:
Originally Posted by mclarke View Post
produce them as both one file for each book and one file for each order (not at the same time - two different production runs).
Yes, so this requires something FusionPro can trigger off of to determine which of those two modes you want the composition to run in. I've made that something to be a hard-coded value in the rule, which you can change to switch from the "one file per book" mode to the "one file per order (record in the main data file)" mode.

However, it would be better, especially in an automated, or "totally hands-off" workflow, to have this specified in the data. I would add another data field (column) to the data file, called something like "OutputBooks", and set it to a value of Yes or No; the rule has some commented-out code showing how that can be accessed.
Originally Posted by mclarke View Post
The customer wants a totally hands-off production run (we're going to be looking at FusionPro Producer if I can get this to work manually) with each order a separate line in the data file.
So in addition to having something in the data to denote which kind of production run you're doing, I would say that a "totally hands-off" workflow would actually require FusionPro Server. FusionPro VDP Producer frees you up from having to initiate each composition/production run in Acrobat, but a human still needs to push the Recompose button in the Producer Monitor app. Only FP Server allows a fully automated workflow, where another process can trigger a composition, via an API call, or by placing a data file in a hot folder, or some other automated mechanism.
Originally Posted by mclarke View Post
Sure, no problem. It's very rough, no graphics, just the text. Before I went to the trouble of "fancying it up", I wanted to make sure I could get the variable pages to work. I don;t even have an imposition yet.
Yes, that's a good way to start.
Originally Posted by mclarke View Post
The three pages are named and marked as unused (as per one of the training videos), so you will have to turn them on.
Yes, so here is another place where I had to guess a bit as to what you want the output to be. My version of the job outputs that "Cover" page at the start of each new book, and then a pair of pages ("Ticket" and "Back") for each ticket.

You presumably want a "Back" page for each Cover page as well, especially if you're imposing, as imposition requires each output record to have the same number of pages. What I would do is add a second Unused page named "Cover Back", and add a second call to FusionPro.Composition.SetBodyPageUsage to activate it along with the main "Cover" page. (This second call is there in the rule, commented out.)

Other than that, you shouldn't need any code to activate the main ticket pages, and those pages should NOT be marked as Unused in the Page Usage.
Originally Posted by mclarke View Post
I hope to get better at all this stuff, but it's hard learning scripting as I try to do this project and also teaching myself MySQL at the same time (needed for another part of the project). So, thank you for looking into this issue for me. I really appreciate it.
No problem! That does seem like a lot to bite off at one time. I'm interested in how you're using SQL as part of this project.
Attached Files
File Type: pdf Sample-Ticket-Book-Dan-1.pdf (33.3 KB, 4 views)
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or

Complex template-building questions, as well as all installation and font questions or problems, should be directed to Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote