Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 13th, 2016, 01:06 PM
MarkJonesEMKT MarkJonesEMKT is offline
Junior Community Member
 
Join Date: Dec 2015
Location: Virgina
Posts: 17
Default Access Job Options in OnNewOutputFile Rule

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.

Code:
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
Reply With Quote
  #2  
Old January 13th, 2016, 01:57 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Access Job Options in OnNewOutputFile Rule

You can determine if the the multiple files box is checked like this:
Code:
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:
Code:
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.
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #3  
Old January 13th, 2016, 02:05 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: Access Job Options in OnNewOutputFile Rule

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.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

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 inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. 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
  #4  
Old January 13th, 2016, 02:21 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: Access Job Options in OnNewOutputFile Rule

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:
Code:
if (CurrentRecordNumber() % 450 == 1)
{
    var new_name = Field("Filename") + "_" + Field("Presort Se") + "_" + 450 + "." + FusionPro.Composition.outputFormatExtension;
    FusionPro.Composition.OpenNewOutputFile(new_name);
}
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

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 inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. 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
  #5  
Old January 13th, 2016, 02:41 PM
MarkJonesEMKT MarkJonesEMKT is offline
Junior Community Member
 
Join Date: Dec 2015
Location: Virgina
Posts: 17
Default Re: Access Job Options in OnNewOutputFile Rule

Thank you so much, I tested this out and it accomplished exactly what I needed. I had seen those fields but they weren't filled because I was looking at them with "preview template."
Reply With Quote
  #6  
Old January 13th, 2016, 02:45 PM
MarkJonesEMKT MarkJonesEMKT is offline
Junior Community Member
 
Join Date: Dec 2015
Location: Virgina
Posts: 17
Default Re: Access Job Options in OnNewOutputFile Rule

Quote:
Originally Posted by Dan Korn View Post
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:
Code:
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!
Reply With Quote
  #7  
Old January 13th, 2016, 03:24 PM
MarkJonesEMKT MarkJonesEMKT is offline
Junior Community Member
 
Join Date: Dec 2015
Location: Virgina
Posts: 17
Default Re: Access Job Options in OnNewOutputFile Rule

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.)
Reply With Quote
  #8  
Old January 13th, 2016, 04:31 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: Access Job Options in OnNewOutputFile Rule

Quote:
Originally Posted by MarkJonesEMKT View Post
Correction, I thought that this was working,
What exactly was it that you thought was working? Can we see the current rule?
Quote:
Originally Posted by MarkJonesEMKT View Post
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?
Quote:
Originally Posted by MarkJonesEMKT View Post
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:
Code:
Print("RecordsPerChunk=" + FusionPro.Composition.JobOptions.RecordsPerChunk);
For good measure, let's add this line as well:
Code:
Print("OutputSource=" + FusionPro.Composition.JobOptions.OutputSource);
Then compose, view the log file, and see what it reports.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

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 inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. 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
  #9  
Old January 14th, 2016, 07:13 AM
MarkJonesEMKT MarkJonesEMKT is offline
Junior Community Member
 
Join Date: Dec 2015
Location: Virgina
Posts: 17
Default Re: Access Job Options in OnNewOutputFile Rule

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

Code:
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!
Reply With Quote
  #10  
Old January 14th, 2016, 08:14 AM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Access Job Options in OnNewOutputFile Rule

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:
Code:
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:
Code:
FusionPro.Composition.forcePreprocessing = FusionPro.Composition.JobOptions["RecordsPerChunk"];
And your OnRecordStart rule would look like this:
Code:
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);
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 06:19 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.