Jump to content

Eliminating Duplicate Code

Recommended Posts

I have 3 templates (1 is attached) each of which uses the same code in the following:

JavaScript Globals





What is the best way to consolidate this code so that it resides in only 1 place? I was able to use the Load function to load an external file that contained the JavaScript Globals within OnJobStart rule, however, I'm concerned that the Global variables and constants are not going to work as intended. In addition, I would like to do something similar with the OnRecordStart, etc, but again, I'm concerned about the Global variables that are being referenced within those rules.


Link to comment
Share on other sites

If you call the Load function in your JavaScript Globals, then any global variables in the .js script file will be global in the context of the job.


That said, I'm not sure you need all that code in the first place to chunk the output to multiple files. I think you can accomplish most of what you need by simply doing this in OnRecordStart:

if (FieldChanged("territoryid"))
       FormatNumber("00000", FusionPro.Composition.recordNumberInChunk) +
       "_File-" + FusionPro.Composition.outputRecordNumber +
       "_UPS-" + Trim(Field("ZoneCode")) +
       "_PRINT_QTY-" + Trim(Field("quantity")) +
       "_TERR-" + Trim(Field("territoryid")) +
       "_" + "_TOTAL_PIECES-" + Trim(Field("TotalPieces")) +
       "_" + Trim(Field("FirstName")) +
       "_" + Trim(Field("lastname")) +
       "." + FusionPro.Composition.outputFormatExtension);

And instead of setting a CUTTER_STACK_BREAK variable in the code, you can check the "Output to multiple files" box on the Output tab of the Composition Settings and set the maximum number of records you want in each output file. Or, you can set FusionPro.Composition.chunksBreakStacks = true in OnJobStart and set the stack size in FP Imposer.

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.

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