Sdawson Posted May 20, 2016 Share Posted May 20, 2016 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. 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. 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. Quote Link to comment Share on other sites More sharing options...
step Posted May 23, 2016 Share Posted May 23, 2016 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); Quote Link to comment Share on other sites More sharing options...
Sdawson Posted May 23, 2016 Author Share Posted May 23, 2016 Thank you, I added both enhancements to my code and it worked great. I didn't even think about getting an odd number of Order Numbers. Great advice. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.