Jump to content

First time using ExternalDataFileEx and PrimaryInputFile


Recommended Posts

Hello, I recently created some code for a project that I pieced together from other posts on this forum and I was wondering if you (the community) could take a look at it. I am trying to fine tune it and get a better understanding of all the cool things FusionPro can do.

 

Background Information

The job had 1,180 unique Order Numbers, 25 records per order number, 29,500 records total. It was 8.5 x 11 and imposed 2up on 11 x 17 duplex. I put them into stacks of 25. Two order numbers per output file.

 

My Issue

I was outputting just the Order Number.pdf and I wanted more information in the file name.

o5fgHMOibBHXMyDgp2yjSIkrznZ-UtkDZX0t-zLLfEs?size=1280x960&size_mode=3

 

So I wrote this code (took me awhile to figure this out) I would like to thank Step and Dan Korn, I have read a few of their posts and borrowed code trying to figure this out.

 

OnNewOutputFile Callback Rule

var CurrentOrderNumber
var NextOrderNumber
var ex = new ExternalDataFileEx(PrimaryInputFile());
var rec = FusionPro.Composition.inputRecordNumber+25;

CurrentOrderNumber = Field("Order_Number")
NextOrderNumber = ex.GetFieldValue(rec, 0);

FusionPro.Composition.OpenNewOutputFile(CurrentOrderNumber + "_" + NextOrderNumber + "." + FusionPro.Composition.outputFormatExtension);

 

Success, I got the results I wanted.

 

QwRhbXQfIx8g_USsRapFwQB8ld_7px_4QQdzy1kcXTw?size=1280x960&size_mode=3

 

It took me awhile to figure out the GetFieldValue(record, FieldNameOrNumber) section. My input file was Tab Delimited so I wasn't sure how to use the ExternalDataFileEx(FileName,Delimiter) correctly and I don't think my FieldNames loaded properly so I ended up using FieldNumbers. Is there another way to call your current input file or is ExternalDataFileEx then PrimaryInputFile the only way to go?

 

Thank you for your time. I had a lot of fun getting this far. I look forward to learning more about this.

Link to comment
Share on other sites

OnNewOutputFile Callback Rule

var CurrentOrderNumber
var NextOrderNumber
var ex = new ExternalDataFileEx(PrimaryInputFile());
var rec = FusionPro.Composition.inputRecordNumber+25;

CurrentOrderNumber = Field("Order_Number")
NextOrderNumber = ex.GetFieldValue(rec, 0);

FusionPro.Composition.OpenNewOutputFile(CurrentOrderNumber + "_" + NextOrderNumber + "." + FusionPro.Composition.outputFormatExtension);

 

It took me awhile to figure out the GetFieldValue(record, FieldNameOrNumber) section. My input file was Tab Delimited so I wasn't sure how to use the ExternalDataFileEx(FileName,Delimiter) correctly and I don't think my FieldNames loaded properly so I ended up using FieldNumbers. Is there another way to call your current input file or is ExternalDataFileEx then PrimaryInputFile the only way to go?

You can specify a tab delimiter and reference the field by name like this if you want:

var ex = new ExternalDataFileEx(PrimaryInputFile(), '\t');
NextOrderNumber = ex.GetFieldValue(rec, 'Order_Number');

 

The code you wrote assumes there will always be two orders in each output file. If you ran a data file that had 1,179 unique records, your last output file would be named something like "1179_.pdf." To avoid that, you could make this slight modification:

var name = [CurrentOrderNumber, NextOrderNumber].filter(String).join('_');
FusionPro.Composition.OpenNewOutputFile(name + "." + FusionPro.Composition.outputFormatExtension);

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