Jump to content

Basic External Data File


rpaterick

Recommended Posts

I have my mail file and external data file(attached).

 

Mail file, field to have the external data file call out is called Master Tier

 

In the external data file, I have 11 fields now to go off of Master Tier field.

 

I tried to modify the items purchased rule from the sample external data sample: http://forums.printable.com/showthread.php?t=392 but got nowhere.

 

I understand how the code works(to a point) but can't figure out how to just get rid of the tax look-up and have the external data file scan the column headers correctly. I would like to have all 11 column headers(from external data file) calling out that I then place the header name in the FusionPro .pdf template.

 

Thanks for any direction.

Formatted.txt

Link to comment
Share on other sites

I got the code working for each individual field. The code below, calls out ADT from the Formatted.txt data file that was attached. I didn't know if there was a cleaner code out there, as I couldn't delete out the "tax equation" without getting an error, or a different way of simplifying.

 

//Create an empty variable that will be populated with a 
//string of text that lists the customer's purchases
returnStr = '';

//The following if statement will detect if we are currently in preview
//mode or editing this rule (versus composing output).  If so, the script
//will manually call the OnJobStart rule so the link to the external 
//data file can be established.  OnJobStart is called automatically when
//a full composition is run.
if(FusionPro.Composition.isPreview == true || FusionPro.inValidation == true)
{
   Rule("OnJobStart");
}


//Get a count of the total number of records in the external data file
numRecsExtDF = externalDF.recordCount;

//Now, loop through all records in the external data file and 
//find the records that belong to the customer.  This is done
//by comparing the value of "CustomerID" from the main input
//data file to the value of the "CID" field in the external data
//file.  
//
//Note that in this example, there can be multiple records in the 
//external data file for each customer which is why we are going to
//look at every record in the external data file.

for (recordWalker=1; recordWalker <= numRecsExtDF; recordWalker++)
{
   //Compare the value of the CID field in the current record
   //we are looking at in the external data file to the value
   //of the CustomerID field in the main data file.
   if (externalDF.GetFieldValue(recordWalker, 'Master Tier') == Field("MT"))
   {
       //Check to see if this is a TAX item.  If it is, let's format it differently
       if (externalDF.GetFieldValue(recordWalker, 'Master Tier') == 'this is not used')
       {
           returnStr += '<br><b>Total Tax - ' + externalDF.GetFieldValue(recordWalker, 'Price') + '</b>';

       }
       else //OK - so this is a normal product - not a Tax item
       {
           returnStr += externalDF.GetFieldValue(recordWalker, 'ADT');
       }
   }
}


return returnStr;

Link to comment
Share on other sites

I don't see why you can't remove that "if" statement, and the corresponding "else", inside the loop, like so:

for (recordWalker=1; recordWalker <= numRecsExtDF; recordWalker++)
{
   if (externalDF.GetFieldValue(recordWalker, 'Master Tier') == Field("MT"))
   {
           returnStr += externalDF.GetFieldValue(recordWalker, 'ADT');
   }
}

Link to comment
Share on other sites

As for obtaining the column headers from the external file, that's simply a matter of getting the value of each field in record zero, i.e. the first line. I'm not sure exactly what you're trying to do with the external data fields in the output, but you can try something like this:

for (var recordWalker = 1; recordWalker <= externalDF.recordCount; recordWalker++)
{
   if (externalDF.GetFieldValue(recordWalker, 'Master Tier') == Field("MT"))
   {
       for (var field = 0; field < externalDF.fieldCount; field++)
       {
           returnStr += externalDF.GetFieldValue(0, field) + ": " + // header from record zero
               externalDF.GetFieldValue(recordWalker, field) + "<br>\n";
       }
   }
}

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...