Jump to content

Rule not returning more than one record


Recommended Posts

I am attempting to create a rule that will cycle through a data list and place the defined fields into a repeatable component template and have each record display one under the next. For some reason my rule is only returning the first record. My rule is below. Any suggestions?

 

var returnString = " ";

var input = FusionPro.Composition.inputFileName;

var ex = new ExternalDataFileEx(input, ',');

var records = ex.recordCount;

 

for (var i = 1; i <= records; i++)

{

beerList = new FPRepeatableComponent("Craft");

beerList.AddTextVar(Field("Beer"), Field("Style"));

 

returnString += beerList;

 

return returnString;

}

Link to comment
Share on other sites

I did that so my rule now looks like this:

 

var returnString = " ";

var input = FusionPro.Composition.inputFileName;

var ex = new ExternalDataFileEx(input, ',');

var records = ex.recordCount;

 

for (var i = 1; i <= records; i++)

{

beerList = new FPRepeatableComponent("Craft");

beerList.AddTextVar(Field("Beer"), Field("Style"));

 

returnString += beerList;

}

 

return returnString;

 

----------------

 

However, now it's repeating the same record multiple times on the page and created separate pages for each record. What I am looking to get is more than one record on the same page.

 

Thanks.

Link to comment
Share on other sites

It's difficult to tell what's going on from seeing just the rule, without the rest of the job. But I think you need to add the keyword "var" before the first instance of "beerList", so that it becomes a new local variable in each iteration of the loop, instead of a global variable which is simply modified each time.

 

Also, of course the same thing is going to be repeated over and over again if all you're doing is calling the Field function in each iteration. The Field function accesses data from your main data file, which is always the same for the record you're composing. (The fact that you're using the main data file as an ExternalDataFileEx doesn't magically change the behavior of the Field function.) You need to access data from the external data file instead, by calling the ExternalDataFileEx.GetFieldValue function. Also, in the call to AddTextVar, I'm fairly certain that you want the first parameter to just be a variable (data field) name (such as "Beer"), not a data field value.

 

Again, I'm not sure if this will really do what you want, since I don't have the rest of the job to test against, but you want to do something like this:

var returnString = "";
var input = FusionPro.Composition.inputFileName || "FileNameForValidationHere.txt";
var ex = new ExternalDataFileEx(input, ',');
var records = ex.recordCount;

for (var i = 1; i <= records; i++)
{
 var beerList = new FPRepeatableComponent("Craft");
 beerList.AddTextVar("Beer", ex.GetFieldValue(i, "Style"));
 returnString += beerList;
}

return returnString;

 

As to why each iteration of the repeatable component is generating its own output page, you probably need to make the Overflow page into which it's being set a little bit taller. But again, that's just a guess, since I don't have the rest of your job to look at.

 

You might also be able to accomplish what you want without using external data or repeatable components at all, by instead simply outputting one page for each record in the data file, and then using Imposition to output those pages "multi-up" onto a press sheet.

Link to comment
Share on other sites

I made the changes suggested, and the output is still the same. Imposition option will not work because I'm trying to build columns on a menu. I have attached a Collection .zip file of a sample of what I'm trying to do if that helps determine what I'm doing incorrectly. Thanks.

15-0102 New Beer Menu_Cumberland TEST.zip

Link to comment
Share on other sites

II have attached a Collection .zip file of a sample of what I'm trying to do if that helps determine what I'm doing incorrectly.

Thanks, this does make it much easier for me to figure out what's going wrong.

I made the changes, and the output is still the same.

Well actually, no, you didn't make the changes I suggested, at least not all of them. I specifically said:

Also, in the call to AddTextVar, I'm fairly certain that you want the first parameter to just be a variable (data field) name (such as "Beer"), not a data field value.

And in my example (again, guessing without having your data file), I had:

  beerList.AddTextVar("Beer", ex.GetFieldValue(i, "Style"));

But in your rule, you have:

    beerList.AddTextVar(ex.GetFieldValue(i, "Beer"), ex.GetFieldValue(i, "Style"));

The call to ex.GetFieldValue(i, "Beer") is going to return something like "Anchor Steam Beer", which is then being used as the first parameter to the call to AddTextVar(), which is going to try to set the value of a text variable named "Anchor Steam Beer" for the template. But the template isn't using a variable named "Anchor Steam Beer", it's using a variable named "Beer", which is why you need to just specify "Beer" as that first parameter.

 

Where the first parameter to AddTextVar() is the name of the variable "Beer", from your data, it looks like the second parameter should be the value of the "Beer" variable from the external data, like so:

    beerList.AddTextVar("Beer", ex.GetFieldValue(i, "Beer"));

What this is saying is: Take the value of from the column "Beer" in the external data, for the row specified by "i", and use that as the variable named "Beer" in the template.

 

Looking at the template, you also have a variable named "Style" being called out, so you need to set that as well, presumably to the value of the "Style" column in the external data. It's the same mapping:

    beerList.AddTextVar("Style", ex.GetFieldValue(i, "Style"));

 

Putting this all together:

// Use the input file name from the design at rule validation time.
var input = FusionPro.Composition.inputFileName || FusionPro.inputFileName;

var ex = new ExternalDataFileEx(input, ',');
var returnString = "";
for (var i = 1; i <= ex.recordCount; i++)
{
   var beerList = new FPRepeatableComponent("Craft");
   beerList.AddTextVar("Beer", ex.GetFieldValue(i, "Beer"));
   beerList.AddTextVar("Style", ex.GetFieldValue(i, "Style"));
   returnString += beerList + "\n\n";
}
return returnString;

This generates what I think is the output you're looking for. (You can see it working if you validate the rule in the Rule Editor as well.) Although, not all of the beer names fit in the first text frame of the template, so they seem to be missing in the output; you can see the red lines denoting text not fitting if you Preview.

 

Also, you probably want an Overflow page so that your list isn't just truncated. That's why I mentioned an Overflow page earlier, as that's the typical usage for something like this. But I was only able to guess at the problem without the job files.

 

Furthermore, you don't need to compose more than one "record" for the job. Each record you compose will have the same list of beers that you get by iterating the data file in the rule. I would just set both the From and To numbers to 1 on the Input tab of the Composition Settings. Or better yet, set the main data source for the job to "None", and just specify the name of the external data file in the rule:

var ex = new ExternalDataFileEx("Cumberland.csv", ',');

Part of the confusion here is that you don't really have a "main" data file for this job. From what I can tell, you're not really trying to compose multiple output pages, one for each beer, you really just want to compose a single list of beers, from a secondary data file, in a single output record.

Imposition option will not work because I'm trying to build columns on a menu.

Okay, now that I see the job, I get that. But still, instead of the template/repeatable component, it seems like it would be much easier, and more straightforward, to just do all of this as a table, like so:

var table = new FPTable;
table.AddColumns(20000, 20000);

var ex = new ExternalDataFileEx("Cumberland.csv", ',');
for (var i = 1; i <= ex.recordCount; i++)
{
   var row = table.AddRow();
   row.SetContents(ex.GetFieldValue(i, "Beer"), ex.GetFieldValue(i, "Style"));
}
return table.MakeTags();

Remember to check the "Treat returned values as tagged text" box. You can tweak the column widths and add table cell borders and such as desired.

 

Although, heck, if the table is simple enough, it can be accomplished with just tabs, like so:

var returnString = "";
var ex = new ExternalDataFileEx("Cumberland.csv", ',');
for (var i = 1; i <= ex.recordCount; i++)
   returnString += ex.GetFieldValue(i, "Beer") + "<t>" + ex.GetFieldValue(i, "Style") + "<br>\n";
return returnString;

Where you just have to click the Tabs button on the Text Editor to set the tab stop position.

Edited by Dan Korn
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...