Jump to content

Output X copies of each record


Recommended Posts

I have a data file with a "Copies" field. This specifies how many of each record will be needed. The values range from 2 to 6, and I want to avoid opening my data file and duplicating records.

 

I have been looking around the forums and it seems the easiest way to do this is a OnRecordStart rule with the following:

 

FusionPro.Composition.repeatRecordCount = Field("Copies");

However, when I compose my document I still only get one copy of each record.

 

Any suggestions?

Link to comment
Share on other sites

what kind of file path is needed for Windows? Will this only work on a MAC?

 

I changed the field name and file paths where it said EDIT HERE and it has an error when validating "File Operation Open Failed" at line 28

if (of.open("create") == false)

 

My rule is below

 

// OnJobStart rule to repeat records

var RepeatFieldName = "Copies";  // EDIT THIS
var FieldDelimiter = "\t";  // EDIT THIS ("\t" for tab-delimited "," for comma)

var orginputfilename = FusionPro.Composition.inputFileName;

// For composition, the original name is set,
// and the new name must be specified as an HFS path on Mac.
// EDIT THIS
var newfilename = "P/D26762_AAN/VD/tempout.txt";

if (FusionPro.inValidation)
{
  // For composition, both names must be specified as POSIX paths on Mac.
  // EDIT THIS
  orginputfilename = "P/D26762_AAN/VD/AwardCertificates.csv";
  // EDIT THIS
  newfilename = "P/D26762_AAN/VD/tempout.txt";
}

// DO NOT EDIT BELOW THIS LINE
var sf = new ExternalDataFileEx(orginputfilename, FieldDelimiter);
if (!sf.valid)
  throw("Unable to open ExternalDataFile: " + orginputfilename);
var of = new File(newfilename);
//of.remove();
if (of.open("create") == false)
  throw("Could not create output file.");
of.close();
if (of.open("write") == false)
  throw("Could not write output file.");
for (var i=0;i<sf.fieldCount;i++)
{
  if (i)
    of.write(FieldDelimiter);
  of.write(sf.GetFieldValue(0, i));
}
of.write("\r\n");
var NewInputTotalRecords = 0;
for (var i = 0 ; i <= sf.recordCount; i++)
{
 var startval = 1;
 var repeatcount = Int(sf.GetFieldValue(i, RepeatFieldName));
 for(var j = 0; j < repeatcount; j++)
 {
   NewInputTotalRecords++;
   for(var k = 0; k < sf.fieldCount; k++)
   {
       if (k)
         of.write(FieldDelimiter);
       switch(sf.GetFieldValue(0, k))
       {
         case RepeatFieldName:
            of.write(startval+j);
            break;
         default:
            of.write(sf.GetFieldValue(i, k));
       }
   }
   of.write("\r\n");
 }
}
of.close();
FusionPro.Composition.inputFileName = newfilename;
var message = orginputfilename + "\n" + sf.recordCount + " records\n\n";
message += FusionPro.Composition.inputFileName + "\n" +  
NewInputTotalRecords + " records";
Print(message);
return message;

Link to comment
Share on other sites

what kind of file path is needed for Windows? Will this only work on a MAC?

It will work on Windows, but you need a valid Windows path, that is, something that you can type into the Windows Start -> Run box and open.

 

I think the problem is that your path needs to start with a drive letter and a colon. So instead of this:

var newfilename = "P/D26762_AAN/VD/tempout.txt";

You probably want this:

var newfilename = "P[color=Green][b]:[/b][/color]/D26762_AAN/VD/tempout.txt";

Assuming you have mapped the "P" drive.

 

But like I said, this is a hard rule to get working, which is why we came up with the much easier way of doing this in FusionPro 6.0.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...