Landisa Posted November 10, 2016 Share Posted November 10, 2016 (edited) [sOLVED] I am working on several items in this field including multiple possible body pages based on column value, overflow, and variable tables based on key customers and multi-row external data. My big issue right now is that my tables display on Preview but nothing shows up during Composition. I am assuming it is simple missed code or misplaced code on my behalf. OnRecordStart if (Field("MCE_Letter_Code") == "1") { FusionPro.Composition.SetBodyPageUsage("PP006", false); FusionPro.Composition.SetBodyPageUsage("PP006_2", false); FusionPro.Composition.SetBodyPageUsage("PP006_3", false); FusionPro.Composition.SetBodyPageUsage("PP006_Overflow",false); FusionPro.Composition.SetBodyPageUsage("PP009", false); FusionPro.Composition.SetBodyPageUsage("PP010", false); FusionPro.Composition.SetBodyPageUsage("PP026", false); } else if (Field("MCE_Letter_Code") == "6") { FusionPro.Composition.SetBodyPageUsage("PP001",false); FusionPro.Composition.SetBodyPageUsage("PP001_2",false); FusionPro.Composition.SetBodyPageUsage("PP001_Overflow",false); FusionPro.Composition.SetBodyPageUsage("PP009", false); FusionPro.Composition.SetBodyPageUsage("PP010", false); FusionPro.Composition.SetBodyPageUsage("PP026", false); } else if (Field("MCE_Letter_Code") == "9") { FusionPro.Composition.SetBodyPageUsage("PP001",false); FusionPro.Composition.SetBodyPageUsage("PP001_2",false); FusionPro.Composition.SetBodyPageUsage("PP001_Overflow",false); FusionPro.Composition.SetBodyPageUsage("PP006", false); FusionPro.Composition.SetBodyPageUsage("PP006_2", false); FusionPro.Composition.SetBodyPageUsage("PP006_3", false); FusionPro.Composition.SetBodyPageUsage("PP006_Overflow",false); FusionPro.Composition.SetBodyPageUsage("PP010", false); FusionPro.Composition.SetBodyPageUsage("PP026", false); } else if (Field("MCE_Letter_Code") == "10") { FusionPro.Composition.SetBodyPageUsage("PP001",false); FusionPro.Composition.SetBodyPageUsage("PP001_2",false); FusionPro.Composition.SetBodyPageUsage("PP001_Overflow",false); FusionPro.Composition.SetBodyPageUsage("PP006", false); FusionPro.Composition.SetBodyPageUsage("PP006_2", false); FusionPro.Composition.SetBodyPageUsage("PP006_3", false); FusionPro.Composition.SetBodyPageUsage("PP006_Overflow",false); FusionPro.Composition.SetBodyPageUsage("PP009", false); FusionPro.Composition.SetBodyPageUsage("PP026", false); } else if (Field("MCE_Letter_Code") == "26") { FusionPro.Composition.SetBodyPageUsage("PP001",false); FusionPro.Composition.SetBodyPageUsage("PP001_2",false); FusionPro.Composition.SetBodyPageUsage("PP001_Overflow",false); FusionPro.Composition.SetBodyPageUsage("PP006", false); FusionPro.Composition.SetBodyPageUsage("PP006_2", false); FusionPro.Composition.SetBodyPageUsage("PP006_3", false); FusionPro.Composition.SetBodyPageUsage("PP006_Overflow",false); FusionPro.Composition.SetBodyPageUsage("PP009", false); FusionPro.Composition.SetBodyPageUsage("PP010", false); } else { } return ""; OnJobStart //Link to the external data file. data = new ExternalDataFileEx("data_feed.csv", ","); if (!data.valid) { ReportError("Cannot successfully read/find the external data file."); } Rule_DataTable //The following if statement will detect if we are currently in preview mode or editing this rule (versus composing output). if(FusionPro.Composition.isPreview == true || FusionPro.inValidation == true) { Rule("OnJobStart"); } //Create empty var table = []; var tbl = []; //Get a count of the total number of records in the external data file NumberOfRecords = data.recordCount; var type = [ [' '] //Header ]; //Create Table var myTable = new FPTable; myTable.AddColumns(13000, 2000, 20000, 8500, 6500); tbl.push(["", "", "Provider Name", "Phone Number", "Miles Away"]); //Header Rows //Now, loop through all records in the external data file and find the records for (var n=1; n<=NumberOfRecords; n++) { function ExField(field) {return data.GetFieldValue(n, field);} if (Field("MCE_Case_Number") == ExField("Case_Number")) { type.forEach(function(s) { var [provider, phone, miles] = s; provider = ExField("Prov_Name"); phone = ExField("Prov_Phone").replace(/^[\D]*(\d{3})[\D]*(\d{3})[\D]*(\d{4})$/, "($1) $2-$3"); miles = FormatNumber("0.0", ExField("Prov_Mileage")/100); tbl.push(['Check to choose this provider', '', provider, phone, miles]); }); } } // Formatting for (var i=0; i<tbl.length; i++) { var row = myTable.AddRow(); var cell = row.Cells[0]; row.minHeight = 2000; cell.Margins = new FPTableMargins; cell.Margins.Bottom = 0; row.CopyCells (0,1,2,3,4); if (i >= 1) myTable.Rows[i].Cells[1].SetBorders ("Thin", "Black", "Top", "Bottom", "Right", "Left"); if (i == 0) cell.HStraddle = 2; myTable.Rows[0].Cells[1].Bold = "On"; cell.VAlign = "Middle"; row.CopyCells (1,2,3,4); myTable.Rows[i].Cells[2].HAlign = "Left"; myTable.Rows[i].Cells[3].HAlign = "Center"; myTable.Rows[i].Cells[4].HAlign = "Right"; var [col0, col1, col2, col3, col4] = tbl[i]; row.SetContents (col0, col1, col2, col3, col4); } myTable.AddRow(1); //Blank row for seperation //Push variable into Array table.push(myTable.MakeTags()); return table; Text Frame If you want a doctor not listed in the chart below, write the name and city on the lines below. Name: City: «Rule_DataTable» Person completing this form: Again I get the results I need from preview but the composition file is well lacking the data table. Suggestions? Another set of eyes on my code helps a lot. Edited November 10, 2016 by Landisa Solved Quote Link to comment Share on other sites More sharing options...
step Posted November 10, 2016 Share Posted November 10, 2016 Are you getting any errors in your message log? Like: "Cannot successfully read/find the external data file."? You could try just defining your data file within the rule itself rather than assigning it to a global variable in OnJobStart: [color="Red"]//Link to the external data file. data = new ExternalDataFileEx("data_feed.csv", ","); if (!data.valid) { ReportError("Cannot successfully read/find the external data file."); } [/color] //Create empty var table = []; var tbl = []; //Get a count of the total number of records in the external data file NumberOfRecords = data.recordCount; var type = [ [' '] //Header ]; //Create Table var myTable = new FPTable; myTable.AddColumns(13000, 2000, 20000, 8500, 6500); tbl.push(["", "", "Provider Name", "Phone Number", "Miles Away"]); //Header Rows //Now, loop through all records in the external data file and find the records for (var n=1; n<=NumberOfRecords; n++) { function ExField(field) {return data.GetFieldValue(n, field);} if (Field("MCE_Case_Number") == ExField("Case_Number")) { type.forEach(function(s) { var [provider, phone, miles] = s; provider = ExField("Prov_Name"); phone = ExField("Prov_Phone").replace(/^[\D]*(\d{3})[\D]*(\d{3})[\D]*(\d{4})$/, "($1) $2-$3"); miles = FormatNumber("0.0", ExField("Prov_Mileage")/100); tbl.push(['Check to choose this provider', '', provider, phone, miles]); }); } } // Formatting for (var i=0; i<tbl.length; i++) { var row = myTable.AddRow(); var cell = row.Cells[0]; row.minHeight = 2000; cell.Margins = new FPTableMargins; cell.Margins.Bottom = 0; row.CopyCells (0,1,2,3,4); if (i >= 1) myTable.Rows[i].Cells[1].SetBorders ("Thin", "Black", "Top", "Bottom", "Right", "Left"); if (i == 0) cell.HStraddle = 2; myTable.Rows[0].Cells[1].Bold = "On"; cell.VAlign = "Middle"; row.CopyCells (1,2,3,4); myTable.Rows[i].Cells[2].HAlign = "Left"; myTable.Rows[i].Cells[3].HAlign = "Center"; myTable.Rows[i].Cells[4].HAlign = "Right"; var [col0, col1, col2, col3, col4] = tbl[i]; row.SetContents (col0, col1, col2, col3, col4); } myTable.AddRow(1); //Blank row for seperation //Push variable into Array table.push(myTable.MakeTags()); return table; Quote Link to comment Share on other sites More sharing options...
Landisa Posted November 10, 2016 Author Share Posted November 10, 2016 Are you getting any errors in your message log? Like: "Cannot successfully read/find the external data file."? You could try just defining your data file within the rule itself rather than assigning it to a global variable in OnJobStart: I tried making that change. No success. As for the Message Log, I have no idea where to find it. I will go looking for it. Quote Link to comment Share on other sites More sharing options...
Landisa Posted November 10, 2016 Author Share Posted November 10, 2016 No errors were found on composition. ====================SUMMARY==================== Collection Directory: C:\Users\AppData\Local\Temp\ ------------------ Composition files: C:\Users\Desktop\FusionPro\Passport Letter_FPro.pdf C:\Users\Desktop\FusionPro\caseworkers.csv Graphics resource files copied: 0 ------------------ Text resource files copied: 0 ------------------ Page media files copied: 0 ------------------ Imposition files copied: 0 ------------------ ------------------ ------------------ ------------------ ------------------ ------------------ Following files are generated for server composition after collect. Data Definition File: Passport Letter_FPro.def DIF format file: Passport Letter_FPro.dif Configuration File: Passport Letter_FPro-o.cfg Unicode Font Files: 4 C:\Users\Public\Documents\PTI\FusionPro\Fonts\Arial Italic-1.pfa C:\Users\Public\Documents\PTI\FusionPro\Fonts\Arial Bold Italic-1.pfa C:\Users\Public\Documents\PTI\FusionPro\Fonts\Arial Bold-1.pfa C:\Users\Public\Documents\PTI\FusionPro\Fonts\Arial-1.pfa Quote Link to comment Share on other sites More sharing options...
step Posted November 10, 2016 Share Posted November 10, 2016 That isn't the composition log; that is the collection log. The composition log would likely be in the same place as your composed output file. Are you composing the output on a different machine than the one you're using to preview the template? I still think that the issue is that your template can't find your external data file at the time of composition. You can try adding an absolute path to your external data file: data = new ExternalDataFileEx("C:\Users\Desktop\FusionPro\data_feed.csv", ","); Or you could add the path to your external data file to the "Search Path" under the "Advanced" tab of the composition settings. Quote Link to comment Share on other sites More sharing options...
Landisa Posted November 10, 2016 Author Share Posted November 10, 2016 That isn't the composition log; that is the collection log. The composition log would likely be in the same place as your composed output file. Are you composing the output on a different machine than the one you're using to preview the template? I still think that the issue is that your template can't find your external data file at the time of composition. You can try adding an absolute path to your external data file: You are a genius! I forgot to add the external file as a Resource. Once I did that the composition worked! *facepalm* Yes, I am previewing the document on a separate machine then composition. Problem Solved! Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted November 10, 2016 Share Posted November 10, 2016 You can try adding an absolute path to your external data file: data = new ExternalDataFileEx("C:\Users\Desktop\FusionPro\data_feed.csv", ","); Please be careful doing this! That code does not do what you expect. Backslashes need to be escaped in JavaScript string literals, like so: data = new ExternalDataFileEx("C:\\Users\\Desktop\\FusionPro\\data_feed.csv", ","); Although, if you really want to hard-code a local path, I would just use forward slashes instead: data = new ExternalDataFileEx("C:/Users/Desktop/FusionPro/data_feed.csv", ","); However, if the job is being composed on a remote Producer machine, then that path is not going to be correct anyway. You probably want to use a UNC path to a shared file server, something like this: data = new ExternalDataFileEx("\\\\fileserver\\share\\subfolder\\etc\\data_feed.csv", ","); But trying to hard-code paths in JavaScript is really not a good idea at all. This is a much better one: Or you could add the path to your external data file to the "Search Path" under the "Advanced" tab of the composition settings. Although, again, you probably want a UNC path there, so that both your local Designer machine and the Producer machine can find the data file. Having said all of that, though, I think the easiest solution is to add the external data file data_feed.csv to the template as a text resource. Then it will get collected up with the job when it's submitted to Producer for composition, and will be found at composition time without having to specify a full path anywhere. Quote Link to comment Share on other sites More sharing options...
Landisa Posted November 14, 2016 Author Share Posted November 14, 2016 Attached FileSample FPro.zip 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.