Jump to content

Access Job Options in OnNewOutputFile Rule


MarkJonesEMKT

Recommended Posts

Hey All,

 

I am still familiarizing myself with all of the capabilities of FusionPro as well as the FP global variables. I am trying to create a rule that will allow me to check the composition settings and check whether or not the "Output to Multiple Files" box is checked. If it is I want to know how many records are output to each file.

 

Here is what I have so far.

 

begin_data=Field("Presort Se");
records_per_file = 450; // Ideally this would be a rule that checked if it needed multiple files and set this number to the record count per file
records_per_file=parseInt(begin_data) + records_per_file - 1;
// Conversion to string
end_data= records_per_file.toString();

// Creation of name 
new_name="Field("Filename") + "_" +  begin_data + "_" + end_data + ".pdf"; 
// CHANGE JOB# NAME AND SECTION
// Sets name of PDF 
FusionPro.Composition.outputFileName= new_name;
return 0; 

 

I looked through all of the building blocks and I saw an object called "Job Options" I wrote a program that showed me all of the fields in that object, but I didn't see anything helpful in there. Is there an object that I am missing? Thanks for any help :)

Link to comment
Share on other sites

You can determine if the the multiple files box is checked like this:

var isChunked = FusionPro.Composition.JobOptions['OutputSource'] == 'bychunk';
return isChunked; // returns true when "Output to multiple files" is selected

 

The number of records in each chunk is accessed by the "RecordsPerChunk" property and since that property will not exist if "Output to multiple files" is not selected during composition, it can also be used to determine if a composition will be chunked:

var recsInChunk = FusionPro.Composition.JobOptions['RecordsPerChunk'];
if (recsInChunk) {
   // Do something if "Output to multiple files" is checked
}

 

As far as your code goes, it appears your aiming to accomplish something very similar to this thread.

Link to comment
Share on other sites

The FusionPro.Composition.JobOptions object has a property/value pair for each entry in the CFG (job options) file. So you can just look at what changes in the CFG file that gets generated when you compose with different settings to see what to key off of.

 

The "Output to multiple files" box and the associated edit boxes on the Output tab of the Composition Settings dialog correspond to the CFG entries "OutputSource", "RecordsPerChunk", and "FirstChunkRecords". In JavaScript, they're these properties:

  • FusionPro.Composition.JobOptions.OutputSource
  • FusionPro.Composition.JobOptions.RecordsPerChunk
  • FusionPro.Composition.JobOptions.FirstChunkRecords

 

The value of the "OutputSource" setting is "bychunk" when the "Output to multiple files" box is checked; otherwise it's "onefile". The other two values correspond to those two edit boxes; "FirstChunkRecords" is undefined (empty) unless the "Different number of records in first file" box is checked.

Link to comment
Share on other sites

Note also that multiple file output (i.e. "chunking") can also be accomplished by calling FusionPro.Composition.OpenNewOutputFile in OnRecordStart, even if the "Output to multiple files" box is not checked. This feature is called "arbitrary chunking." If you use that, then your rule can decide how many records are output to each file, instead of needing to query the CFG options to find out. If you want to start a new file for every 450 records, your OnRecordStart rule could do something like this:

if (CurrentRecordNumber() % 450 == 1)
{
   var new_name = Field("Filename") + "_" + Field("Presort Se") + "_" + 450 + "." + FusionPro.Composition.outputFormatExtension;
   FusionPro.Composition.OpenNewOutputFile(new_name);
}

Link to comment
Share on other sites

Note also that multiple file output (i.e. "chunking") can also be accomplished by calling FusionPro.Composition.OpenNewOutputFile in OnRecordStart, even if the "Output to multiple files" box is not checked. This feature is called "arbitrary chunking." If you use that, then your rule can decide how many records are output to each file, instead of needing to query the CFG options to find out. If you want to start a new file for every 450 records, your OnRecordStart rule could do something like this:

if (CurrentRecordNumber() % 450 == 1)
{
   var new_name = Field("Filename") + "_" + Field("Presort Se") + "_" + 450 + "." + FusionPro.Composition.outputFormatExtension;
   FusionPro.Composition.OpenNewOutputFile(new_name);
}

 

 

I was going to try something like this, but I am trying to prepare templates for people who won't be able to code and I want them to be able to use the CFG and not realize what is going on in the background. Thanks for the help!

Link to comment
Share on other sites

Correction, I thought that this was working, but it was not naming the files correctly. For some reason it isn't pulling the "RecordsPerChunk" information. I can get everything else to work, but it acts like that variable isn't there (Even though it will compile when I am using it.)
Link to comment
Share on other sites

Correction, I thought that this was working,

What exactly was it that you thought was working? Can we see the current rule?

but it was not naming the files correctly.

What is the correct result you're expecting? What is it that you're actually getting? And precisely how are they different?

For some reason it isn't pulling the "RecordsPerChunk" information. I can get everything else to work, but it acts like that variable isn't there (Even though it will compile when I am using it.)

Instead of just wondering why it seems like that variable isn't there, why don't we find out for sure whether it's there and what its value is? Add these lines at the start of your rule:

Print("RecordsPerChunk=" + FusionPro.Composition.JobOptions.RecordsPerChunk);

For good measure, let's add this line as well:

Print("OutputSource=" + FusionPro.Composition.JobOptions.OutputSource);

Then compose, view the log file, and see what it reports.

Link to comment
Share on other sites

This is what I had been doing. I wanted to make sure that the PDF name was not dependent on the job title so I had two different "name" statements that I separated based on the existence of "RecordsPerChunk".

 

var jobtitle = "Job_#_";
var chunkSize = FusionPro.Composition.JobOptions["RecordsPerChunk"];
if(FusionPro.Composition.inputRecordNumber % chunkSize == 1)
{
   var beginfile = FusionPro.Composition.inputRecordNumber;
   var outputName1 = jobtitle + Field("Filename") + "_" + beginfile + "_" + (beginfile + (chunkSize-1));
   FusionPro.Composition.OpenNewOutputFile(outputName1 + "." + FusionPro.Composition.outputFormatExtension);
   if(boolflag == 0)
   {
       boolflag = 1;
   }
}
if(boolflag == 0)
{
var InputType = "";
if (FusionPro.inputFileName.indexOf("_ALL") > -1)
    InputType = "ALL";    
if (FusionPro.inputFileName.indexOf("_LS") > -1)
   InputType = "LS";
var outputName2 = jobtitle + Field("Filename") + "_" + InputType; 
FusionPro.Composition.OpenNewOutputFile(outputName2 + "." + FusionPro.Composition.outputFormatExtension);
boolflag = 1;
}

 

If the file was supposed to split on multiple outputs I wanted to receive the file name

 

Job_#_FILENAME_firstRecord_lastRecord.pdf

 

and if it wasn't I wanted the file name to be

 

Job_#_FILENAME_InputFile.pdf

 

What was happening last night is when I went to compose with the multiple file selection checked and a set chunk size, it was outputting the first PDF with the second filename option, and the rest with the default

JobTitle-Output#.pdf

 

However, when I composed this morning, it worked like it was supposed to. I never figured out why it wasn't working last night, but I thought my code looked right. It is working now though, thank you for your help!

Link to comment
Share on other sites

I think you're going to want to convert the "chunkSize" variable to an integer using the "Int" function.

 

What is the purpose of the "boolflag" variable? Are you including that as some sort of exit status for the function? If so, that's not necessary. If you're using it to determine whether the job is being chunked or not, as I said in my other post, you can determine that based on the "chunkSize" variable.

 

The correct way to access the input file's name is FusionPro.Composition.inputFileName. FusionPro.inputFileName will not return anything and your "outputName2" will end in a trailing underscore (_) as a result. Using the "building blocks" will allow you to access the properties of the FusionPro object as well as give a description. From the Building Blocks, click Objects > FusionPro (Global) > Composition > Input and Output > inputFileName. Double-clicking on the "inputFileName" will insert it into your rule editor.

 

I would consider changing your code to something like this for:

var output = 'Job_#_' + Field('Filename');
var input = FusionPro.Composition.inputFileName;
var chunkSize = Int(FusionPro.Composition.JobOptions["RecordsPerChunk"]);
var beginfile = FusionPro.Composition.inputRecordNumber;
var range = beginfile + (chunkSize-1);

output += chunkSize ? '_' + beginfile + '_' + range : (input.match(/_ALL|_LS/) || [''])[0];

if (beginfile % chunkSize == 1 || beginfile == 1)
FusionPro.Composition.OpenNewOutputFile(output + '.' + FusionPro.Composition.outputFormatExtension);

 

Of course the above code just adds the chunk size to the end of the file name and it may not truly reflect what records are in the file. For example, if you have a 55 record data file set to chunk in sets of 10, your last file would be named "Job_#_FILENAME_51_60.pdf" when it should be named "Job_#_FILENAME_51_55.pdf".

 

To handle that scenario, you'd have to force FusionPro to preprocess the job by putting this in an "OnJobStart" callback:

FusionPro.Composition.forcePreprocessing = FusionPro.Composition.JobOptions["RecordsPerChunk"];

 

And your OnRecordStart rule would look like this:

var output = 'Job_#_' + Field('Filename');
var input = FusionPro.Composition.inputFileName;
var totalRecords = FusionPro.Composition.totalRecordCount;
var chunkSize = Int(FusionPro.Composition.JobOptions["RecordsPerChunk"]);
var beginfile = FusionPro.Composition.inputRecordNumber;
var range = beginfile + (chunkSize-1);

if (range >= totalRecords)
range = totalRecords;

output += chunkSize ? '_' + beginfile + '_' + range : (input.match(/_ALL|_LS/) || [''])[0];

if (beginfile % chunkSize == 1 || beginfile == 1)
FusionPro.Composition.OpenNewOutputFile(output + '.' + FusionPro.Composition.outputFormatExtension);

Link to comment
Share on other sites

What is the purpose of the "boolflag" variable? Are you including that as some sort of exit status for the function? If so, that's not necessary. If you're using it to determine whether the job is being chunked or not, as I said in my other post, you can determine that based on the "chunkSize" variable.

 

The boolflag is an external "global variable," I used it so that my "output2" naming convention would only get called once, and would not get called when I was using the "output1" naming convention. I could have used "chunkSize", but then I would have had to check another flag anyway which is why I chose not to handle it like that.

 

The correct way to access the input file's name is FusionPro.Composition.inputFileName. FusionPro.inputFileName will not return anything and your "outputName2" will end in a trailing underscore (_) as a result. Using the "building blocks" will allow you to access the properties of the FusionPro object as well as give a description. From the Building Blocks, click Objects > FusionPro (Global) > Composition > Input and Output > inputFileName. Double-clicking on the "inputFileName" will insert it into your rule editor.

 

This is actually what I thought too, however "FusionPro.Composition.inputFileName" returns null while "FusionPro.inputFileName" returns the correct naming convention. I actually used the building blocks to double check and it added it as "FusionPro.inputFileName"

 

To handle that scenario, you'd have to force FusionPro to preprocess the job by putting this in an "OnJobStart" callback: ....

 

Thank you for this! I was actually looking into how I could accomplish this.

Link to comment
Share on other sites

The boolflag is an external "global variable," I used it so that my "output2" naming convention would only get called once, and would not get called when I was using the "output1" naming convention. I could have used "chunkSize", but then I would have had to check another flag anyway which is why I chose not to handle it like that.

 

Okay, I think I understand what you're saying. That's basically what I was doing by opening a new output file at the start of a chunk or the first record in the data file.

 

This is actually what I thought too, however "FusionPro.Composition.inputFileName" returns null while "FusionPro.inputFileName" returns the correct naming convention. I actually used the building blocks to double check and it added it as "FusionPro.inputFileName"

 

Okay, if you say so. I don't know what version of FusionPro you have installed but I'm running version 8 and as of version 8 the input file is accessed by FusionPro.Composition.inputFileName just as it's inserted by the "Building Blocks." I'm not saying that they couldn't have changed it in later versions of the software but that seems like something that would have disrupted existing templates that relied on that property. And you'll have to be a little more specific when you say it "returns null" or "returns the correct naming convention." Do you mean in validation or preview? Or are you actually composing the file to see if it's been named like you'd expect? The template can't return the name of the input file until the file is being composed so you'd need to compose the job to check the naming convention.

Link to comment
Share on other sites

Okay, if you say so. I don't know what version of FusionPro you have installed but I'm running version 8 and as of version 8 the input file is accessed by FusionPro.Composition.inputFileName just as it's inserted by the "Building Blocks." I'm not saying that they couldn't have changed it in later versions of the software but that seems like something that would have disrupted existing templates that relied on that property. And you'll have to be a little more specific when you say it "returns null" or "returns the correct naming convention." Do you mean in validation or preview? Or are you actually composing the file to see if it's been named like you'd expect? The template can't return the name of the input file until the file is being composed so you'd need to compose the job to check the naming convention.

As of FusionPro VDP version 9.2, both FusionPro.Composition.inputFileName and FusionPro.inputFileName are valid properties. But they're not exactly the same, and it's important to understand the differences:

  • FusionPro.inputFileName returns the input data file name from the data definition, as specified at template design time in FP VDP Creator in Acrobat. At rule validation time, in the Rule Editor, this returns the input file path and name, if any. (It can still return an empty string if the input type is "None".) At composition time, this may not be the actual data file being processed.
  • FusionPro.Composition.inputFileName returns path and name of the data file actually being processed in a FusionPro Server, Producer, or Creator composition, at composition time. This is usually different than the input file specified at template design time. At rule validation time, in the Rule Editor, this always returns an empty string. (This is the same as the rest of the FusionPro.Composition properties, which do not return anything meaningful at rule validation time, since there isn't actually a composition occurring.) Note that this property works exactly the same way as in previous versions of FusionPro.

There's also a new helper function PrimaryInputFile(), which (except in the case of "None" input) returns an appropriate file path and name at both rule validation and composition time. This was added to aid in creating rules such as the one in this thread, where you need to have a file name to validate the rule in the editor, but you also need to deal with the actual data file being composed at composition time.

 

So in FusionPro 9.2 or later, I would recommend using the PrimaryInputFile() function instead of either the FusionPro.Composition.inputFileName or FusionPro.inputFileName properties.

Link to comment
Share on other sites

There's also a new helper function PrimaryInputFile(), which (except in the case of "None" input) returns an appropriate file path and name at both rule validation and composition time. This was added to aid in creating rules such as the one in this thread, where you need to have a file name to validate the rule in the editor, but you also need to deal with the actual data file being composed at composition time.

 

Oh, that's definitely useful! Thanks for the clarification, Dan. I will (finally) be switching over to FP9 next week so I won't have to keep hypothesizing about all of its features :D

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