Jump to content

For Loop Help


Recommended Posts

Hi, I am trying to get the loop below to run through the record count and execute different results based on the quantity.

 

The rule below never gets past the first if statement.

Not sure what I am doing wrong. Any help would be appreciated.

 

var nameFieldName = "first";

var data = new ExternalDataFileEx(PrimaryInputFile());

var totalRecs = data.recordCount;

 

for (i = 0; i < totalRecs; i++) {

if (totalRecs = 5000) {

var recordsPerBox = (2500);

} else if ((totalRecs > 2500) && (totalRecs < 5000)) {

var recordsPerBox = Math.ceil(totalRecs / 2);

} else (totalRecs < 2500) {

var recordsPerBox = (totalRecs);

}

}

 

var numBoxes = Math.ceil(totalRecs / recordsPerBox);

FusionPro.Composition.repeatRecordCount = numBoxes;

var boxNum = FusionPro.Composition.repeatRecordNumber;

var boxStartRec = (boxNum - 1) * recordsPerBox + 1;

var boxEndRec = Math.min(boxNum * recordsPerBox, totalRecs);

 

FusionPro.Composition.AddVariable("totalRecs", totalRecs);

FusionPro.Composition.AddVariable("boxNum", boxNum);

FusionPro.Composition.AddVariable("numBoxes", numBoxes);

FusionPro.Composition.AddVariable("boxStartRec", boxStartRec);

FusionPro.Composition.AddVariable("boxEndRec", boxEndRec);

FusionPro.Composition.AddVariable("boxStartName", data.GetFieldValue(boxStartRec, nameFieldName));

FusionPro.Composition.AddVariable("boxEndName", data.GetFieldValue(boxEndRec, nameFieldName));

Link to comment
Share on other sites

That totalRecs variable is simply a number, not an array, so there's nothing to iterate over in a for loop.

 

I'm not sure exactly what the requirements are that you're trying to meet with this code, but I think you want to do something like this:

var data = new ExternalDataFileEx(PrimaryInputFile());
var recordsPerBox = Math.ceil(data.recordCount / 2);
if (recordsPerBox < 2500)
   recordsPerBox = 2500;

Or just:

var data = new ExternalDataFileEx(PrimaryInputFile());
var recordsPerBox = Math.ceil(Math.max(data.recordCount, 5000) / 2);

Link to comment
Share on other sites

That totalRecs variable is simply a number, not an array, so there's nothing to iterate over in a for loop.

 

Thank you Dan. That helps. I was getting frustrated trying to figure out a formula that would loop through the totalRecs until zero. I understand my error now.

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