Jump to content

Having Trouble with new table


KrazyKarl

Recommended Posts

Hello, I haven't used FP in four years; now I'm back in the fray and feel like I'm more lost than I ever was back then. I'm far from JS fluent, but I can usually look at similar works (like my old files, which I have) and deduce how to get it to do what I want.

 

I am tasked with creating a price book for client (liquor distributor). I have worked up a table that should repeat from their data. It will eventually have product breaks for wine origins (California, Oregon, etc.) which is included in the data table. I've got some other items in mind as far as alternating shading, etc.

 

For now, however, I can't get the table to flow past the first line of data. I've been beating my head against this in my spare time for a couple days now, and I know it must be totally obvious what I'm doing wrong- but I'm not seeing it at all. The table generates, line 1 looks just like I want... but no more lines. I have tried different things from different threads on here, and I'm nowhere.

 

So - sorry for my noob-ness, but any prod in the right direction would be appreciated! I've included the collection; it's Product Table that isn't doing what I need.

 

I also know that I should be able to apply the different font Open Sans Condensed for all the header cells in one line, but I'm coding that wrong also apparently. The way I have it isn't elegant, but it works...

 

TIA for all you guys do.

 

Karl

WWinsidepage.zip

Link to comment
Share on other sites

Try putting this in your OnRecordStart callback. Then you can get rid of OnJobStart and ProductTable rules.

var keyField = 'Origin';
FusionPro.Composition.composeThisRecord = FieldChanged(keyField);

var data = new ExternalDataFileEx(PrimaryInputFile(), ',');
var recs = data.FindRecords(keyField, Field(keyField));
var table = new FPTable();
table.AddColumns(5000,8000,4600,3500,4000,4000,3500,4000,15600);

var header = table.AddRow();
header.Type = 'Header';
header.Cells[0].Font = 'Open Sans Condensed';
header.CopyCells(0,1,2,3,4,5,6,7,8);
header.SetContents("Item #", "Product Name", "Vintage", "Size", "Units", "Case $", "Btl $", "Sale $", "Ratings");

for (var rec in recs) {
 // Helper function.
 function ExField(str) { return data.GetFieldValue(recs[rec], str); }
 var row = table.AddRow();
 var content = ["Product ID","Product","Vintage","Size","Case Pack","Case Price","Bottle Price","Sale Price","Notes"].map(ExField);
 row.SetContents.apply(row, content);
}

var productTable = table.MakeTags();

FusionPro.Composition.AddVariable("ProductTable", productTable, true);

Link to comment
Share on other sites

Step's solution is great, but there's an even simpler one.

 

In the Data Source Wizard, on the "Data Fields - Flat File" step, check the "Multi-line records" box.

 

http://forums.pti.com/attachment.php?attachmentid=1721&stc=1&d=1502727549

 

Then select "Origin" from the fields list on the next step.

 

http://forums.pti.com/attachment.php?attachmentid=1722&stc=1&d=1502727555

 

Then you don't need any callback rules at all, and your ProductTable rule can be this:

var table = new FPTable();
table.AddColumns(5000,8000,4600,3500,4000,4000,3500,4000,15600);
var header = table.AddRow();
header.Type = 'Header';
header.Cells[0].Font = 'Open Sans Condensed';
header.CopyCells(0,1,2,3,4,5,6,7,8);
header.SetContents("Item #", "Product Name", "Vintage", "Size", "Units", "Case $", "Btl $", "Sale $", "Ratings");

var data = FusionPro.GetMultiLineRecords();
for (var rec = 1; rec <= data.recordCount; rec++)
{
 function ExField(str) { return TaggedTextFromRaw(data.GetFieldValue(rec, str)); }
 var content = ["Product ID","Product","Vintage","Size","Case Pack","Case Price","Bottle Price","Sale Price","Notes"].map(ExField);
 var row = table.AddRow();
 row.SetContents.apply(row, content);
}
return table.MakeTags();

Besides using less JavaScript, the other benefit of using Multi-line records is that the Preview Record Selector will show the same records as in composed output.

multi-line.png.8cbf9ed38474e01226e67caecd664fa8.png

multi-line-2.png.c8f6d2606067075a9da9df3ffb982bc1.png

Link to comment
Share on other sites

Thanks to both of you for the help! I had plugged in Step's option this morning, and it was working fine. I tweaked some column widths and was about to post a thanks to him when I saw Dan's option. Finally got a chance to plug that in, and it is giving me an error.

When I compose, it shows "Value for variable ProductTable not found in instance data". I copied and pasted your code over the previous rule, Dan, and reimported the data as multi line as you showed. The only change I made was the column widths to my new measurements - which if those were off it should just push to second lines, not fail the table. I can go back to Step's version, but thought I would mention it to make sure I'm not missing something else?

 

Thanks again!

Link to comment
Share on other sites

Is the code in a rule named "ProductTable"?

Well, no. Sorry. I copied it into the OnRecordStart that I was working on with Step's solution. So I placed it back in a rule called ProductTable and now it shows the value - but I'm back to only having the first row of data appear.

 

When I compose the first 20, it repeats the error "Failed to find master page <newpage1>

Master page newpage1 not found." for each record. I'm not seeing a call for newpage1 in the rule, though.

Link to comment
Share on other sites

Well, no. Sorry. I copied it into the OnRecordStart that I was working on with Step's solution.

That's why I wrote this:

Then you don't need any callback rules at all, and your ProductTable rule can be this:

So I placed it back in a rule called ProductTable and now it shows the value - but I'm back to only having the first row of data appear.

Well, it works for me. With the rule I included in my previous post, I get all the rows of data for each "Origin" set in the output table.

 

Perhaps you didn't copy the rule I posted exactly? Forgive me, but quite frankly, I'm now skeptical that you followed the rest of what I wrote precisely. I also suspect that you have made other changes that I have no way of seeing.

When I compose the first 20, it repeats the error "Failed to find master page <newpage1>

Master page newpage1 not found." for each record. I'm not seeing a call for newpage1 in the rule, though.

That sounds like the Overflow page is not being found. Do you still have an Overflow page named "newpage1" in the job? Again, it seems like you changed something else in the job that is unrelated to the changes I enumerated.

 

I suppose if you want to attach the job in its current form, I could take another look at it.

Link to comment
Share on other sites

Sorry, Dan, I'm not sure what I had done. I'm certainly not trying to cause an issue, and I definitely appreciate the help you guys are providing.

 

I went back to the file I had uploaded, made the changes you spec'd, and it all flows in. Whatever other change I had made was clearly the issue. So now I have the data flowing in as expected - thanks so much for your assistance.

 

Now I can get on to the other details on the job layout. Thank you for your help.

Link to comment
Share on other sites

Just when you thought it was safe... So the client loved the proofs I came up with from the last edits. That got them thinking though, and now they have some new ideas.

The way the tables were set, I was placing the <Origin> field in the black bar, then listing all of California. When Origin changed, a new page began and the next set began (Oregon, etc.). The client would like to have no page breaks between Origins, so when California ends, the Oregon bar appears and that list starts.

I've played around with this a couple of ways; to my slow mind, I don't see a good way to do that with the Origin bar in a separate box. I can place it as an inline graphic in the text box, but I was thinking about a repeatable component. I have created that template and placed it in a new rule ProductTable2; the Origin bar appears but the table doesn't start composing after.

 

Finally, they would like the producer (winery, distillery, etc.) appearing as a new column - but only when it changes, so it acts as a divider. The logical way to do this seems to be defining the data file by Producer instead of Origin - but this creates a potential issue with the Origin bar solution.

 

So I guess I have several questions -

1) How would you suggest running this solution so there are not page breaks between Origins?

2) Can I define by two variables in a multi-line record to utilize the Origin bar but also use the Producer as a variable?

3) Can I put the repeating component in the same box with a table?

4) Most importantly, when will I learn to say no to clients?

 

Thanks for your advice and expertise. I'm seeing what they want to achieve, but struggling to picture how to create it.

WWinsidepageREPEATABLE8-15.zip

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