dmp Posted February 10, 2017 Share Posted February 10, 2017 Hi awesome peoples, I used to use this for making multiple pdf's based on trays. What I'm wondering is if this can be adapted to make a pdf based on a field that is not in order in the data. For example, I've got a mail list that will imprint a PDF using two different shells. So I have to have two separate pdfs based on shell #1 or shell #2. But I would like them to be in the correct sort/tray order. In this case the field is named Signator and will have one of two people in the field. So 1. bob 2. bob 3. mary 4. bob 5. mary And I'd like to have two pdfs made; 1. bob 2. bob 4. bob and 3. mary 5. mary if (CurrentRecordNumber() == 1) PrevTrayNum = Trim(data.GetFieldValue(StartRow[0], "Tray")); else PrevTrayNum = Trim(data.GetFieldValue(StartRow[CurrentRecordNumber()-2], "Tray")); CurrentTrayNum = Trim(data.GetFieldValue(StartRow[CurrentRecordNumber()-1], "Tray")); if (PrevTrayNum != CurrentTrayNum) FusionPro.Composition.outputFileName = "Test_Output_" + CurrentTrayNum + ".pdf"; Am I correct in thinking this code will overwrite the pdf each time the field changes from one person to the other? So I'd only end up with: 4. bob and 5. mary Thanks and sorry If I'm not writing clearly. I'm super confused with code as it is - Mike Quote Link to comment Share on other sites More sharing options...
step Posted February 11, 2017 Share Posted February 11, 2017 JavaScript Globals names = {}; OnRecordStart var fieldKey = 'Signator'; // Key to sort on // Only compose unique fieldKeys FusionPro.Composition.composeThisRecord = names[Field(fieldKey)] == undefined; // Link to Primary data file as external data file (comma delimited) var data = new ExternalDataFileEx(PrimaryInputFile(), ','); // Get an array of fields whose fieldKey value match that of the current record var cursor = data.SortBy(fieldKey).FindRecords(Field(fieldKey)); // Repeat this record based on the number of matches FusionPro.Composition.repeatRecordCount = cursor.length; // Open a new output file at the start of the record's composition if (FusionPro.Composition.repeatRecordNumber == 1) FusionPro.Composition.OpenNewOutputFile('Test_Output_' + Field(fieldKey) + ".pdf"); // Flag this fieldKey as done if (FusionPro.Composition.repeatRecordNumber == cursor.length) names[Field(fieldKey)] = false; // Remap the fields for each iteration of the repeat for (var field in FusionPro.Fields) FusionPro.Composition.AddVariable(field, data.GetFieldValue(cursor[FusionPro.Composition.repeatRecordNumber-1], field)); Howbowdah? Quote Link to comment Share on other sites More sharing options...
dmp Posted February 11, 2017 Author Share Posted February 11, 2017 Thanks Step! When I put this in there, it gives me this error: ***Error*** (OnRecordStart, line 14: Error: In ExternalDataFileEx.SortBy(), no field named Signator) But I have a field called Signator, I can even drop it in with the building blocks. Am I supposed to change something in particular in the code to match my data? Cheers, Mike Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted February 11, 2017 Share Posted February 11, 2017 Thanks Step! When I put this in there, it gives me this error: ***Error*** (OnRecordStart, line 14: Error: In ExternalDataFileEx.SortBy(), no field named Signator) But I have a field called Signator, I can even drop it in with the building blocks. Am I supposed to change something in particular in the code to match my data? Cheers, Mike Is your data file comma-delimited? You might want to change the line creating the ExternalDataFileEx object to this: var data = new ExternalDataFileEx(PrimaryInputFile(), FusionPro.inputFileDelimiter); 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.