Jump to content

LOOP help


dmsawyer

Recommended Posts

Help! I am new to FP and do not know JS. I am trying to loop through the data file and return a date range for employee time cards for the year. Here is what I have come up with,

 

var Ranges = new Array(“1/4/2010 1/10/2010 02-1”, “1/11/2010 1/17/2010 02-2”, … );

for (var i = 0; i < Ranges.length; i++)

{

if (Field(“Name”) > 0)

{

return Ranges;

}

}

 

Error "Function does not return a value."

 

I am using FP Desktop 6.0.6.0

Windows XP

Acrobat 8.0 Professional

Link to comment
Share on other sites

I'm not sure I understand what you're trying to do. Can you provide a bit more information, maybe a snippet of the data file and what the expected output for each record would be? Are you expecting to output multiple records on separate sheets, or are you trying to aggregate all the data into one record of output?

 

Also, when you say, "loop through the data file," do you mean the main input file for the job, or a secondary data file? You may need to use the ExternalDataFileEx object, certainly for a secondary file, but possibly for the main data file as well, depending on what your data looks like and what your goal is.

Link to comment
Share on other sites

Have uploaded txt file and sample pdf of finished product.

Highlighted section on pdf is the payperiod column in txt file, that we are

trying to change with every loop (when the name column loops around to the beginning).

I don't see an exact match-up from the input data to your sample output, so I'm still not 100 percent sure what the goal is. What exactly do you mean by, "when the name column loops around to the beginning?" In your sample, it looks like you simply have one record (line) of data for each name. Is this not always the case? As far as I can tell, this is actually a pretty simple "one-to-one" job where you just want to have each record of data generate its own output record. So I don't think there's any need for a "loop" at all. But I may still be missing something.

Link to comment
Share on other sites

The results we are trying to get are time cards for each employee for an entire year, we are starting this job in the middle of the physical year so we only need 24 total for each employee. I would like for each name to print from the "List#80.txt" and print the same date range for each name from "Period Dates.txt", one record per impression till the end of the names in the List#80 txt file, then start over printing the first name again with the next date range until the end of the names and start over again with the first name and new date range 24 times. I thought this would be a loop but as I said I am new to FP and JS so I don't really know what to do but know it can be done. Attached are the original data files I received. Thanks again!:eek:

LIST#80.txt

PERIOD DATES.txt

Link to comment
Share on other sites

The results we are trying to get are time cards for each employee for an entire year, we are starting this job in the middle of the physical year so we only need 24 total for each employee. I would like for each name to print from the "List#80.txt" and print the same date range for each name from "Period Dates.txt", one record per impression till the end of the names in the List#80 txt file, then start over printing the first name again with the next date range until the end of the names and start over again with the first name and new date range 24 times. I thought this would be a loop but as I said I am new to FP and JS so I don't really know what to do but know it can be done. Attached are the original data files I received. Thanks again!:eek:

Okay thanks. Seeing both files, I think I understand now. We've got two data files, which we want to basically merge in a relational way.

 

It's really just a slight customization of the Repeat Record example:

http://forums.printable.com/showthread.php?t=391

 

So, one of the data files can be our main input file, and the other can be a secondary file, accessed via the ExternalDataFileEx object. We can use either file as the primary or secondary input, but for this example, I've chosen LIST#80.txt as the main input file for the job and "PERIOD DATES.txt" as the secondary file. I have this logic in the OnRecordStart callback rule:

var PeriodDatesFile = new ExternalDataFileEx("PERIOD DATES.txt", "\t");
if (!PeriodDatesFile.valid)
 throw "Unable to access PERIOD DATES.txt";

FusionPro.Composition.repeatRecordCount = PeriodDatesFile.recordCount;

var dateIndex = FusionPro.Composition.repeatRecordNumber;

FusionPro.Composition.AddVariable("Actual START", PeriodDatesFile.GetFieldValue(dateIndex, "START"));
FusionPro.Composition.AddVariable("Actual END", PeriodDatesFile.GetFieldValue(dateIndex, "END"));
FusionPro.Composition.AddVariable("Actual PERIOD #", PeriodDatesFile.GetFieldValue(dateIndex, "PERIOD #"));

And this is what I have in a text box in the job:

«PS CODE»
«Name»
«Pers.no.»
«Text»
«Actual START» «Actual END» «Actual PERIOD #»

I think this is basically what you want. There are actually two "loops," but one of them is just the sequential reading of the main input file, as in any other FusionPro job. The other is implemented in the code above for the secondary data file.

Link to comment
Share on other sites

  • 2 weeks later...

:)Thanks Dan. I have finally made time to get back to this job and what you sent does work but I really need the time cards to be grouped together for each time period. The way they are now they are grouped together for each person. Any suggestions would help.

Thanks again,

Diane

Link to comment
Share on other sites

:)Thanks Dan. I have finally made time to get back to this job and what you sent does work but I really need the time cards to be grouped together for each time period. The way they are now they are grouped together for each person. Any suggestions would help.

Just skimming through Dan's earlier response, it looks like you would need to swap your primary input file and external input file if you want to switch from personnel groups to time period groups.

 

Of course this would change your PeriodDatesFile to PersonnelFile (as an example), and instead of adding variables "Actual START", "Actual END", and "Actual PERIOD #", you would instead add the variables from your external LIST #80 file.

 

I didn't personally look at your previously uploaded data files, but depending on your field names, Dan's text rule might need to be updated to match field names as well.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...