Jump to content

External Data file


rpaterick

Recommended Posts

I was able to pull from Column B just fine with the code below(not cleaned-up from the tutorial) but now I'm confused as to how to get to another column to pull from? sample data attached. First column A, is what I use to pull from the main mail list.

//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, 'Tier') == Field("Tier"))
   {
       //Check to see if this is a TAX item.  If it is, let's format it differently
       if (externalDF.GetFieldValue(recordWalker, 'Product-Purchased') == 'Tax')
       {
           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, 'Offer1');

       }
   }
}


return returnStr;

sample of external data.txt

Link to comment
Share on other sites

I was able to pull from Column B just fine with the code below(not cleaned-up from the tutorial) but now I'm confused as to how to get to another column to pull from? sample data attached. First column A, is what I use to pull from the main mail list.

I'm not sure what you mean by "Column B" and "Column A", since neither of those are referenced in either the code you posted or in the data file.

 

Do you mean that you want to get the data from a different field (column) in the external data file? Just call out the field by name in the call to

externalDF.GetFieldValue. For instance, if you want the "Offer2" field, just call it out like so:

returnStr += externalDF.GetFieldValue(recordWalker, 'Offer2');

It would be easier to offer more specific suggestions if you could post most more specific information about what you're trying to accomplish, ideally including an example of what the output should look like.

Link to comment
Share on other sites

 

Do you mean that you want to get the data from a different field (column) in the external data file? Just call out the field by name in the call to

externalDF.GetFieldValue. For instance, if you want the "Offer2" field, just call it out like so:

returnStr += externalDF.GetFieldValue(recordWalker, 'Offer2');

 

Correct, just want to pull another column in the external file that would be called the rule also.

 

In the code, I tried to put Offer2 and it returns nothing. Offer 1 pulls just fine but can't get Offer2 or any other columns to display.

Link to comment
Share on other sites

The problem is in your data file. There's an embedded line feed character in the data, in the "Misc1" field in record 1, after ""Don't have a PIN Number?" * Other fields contain embedded line feed characters as well. You can see this if you view the file in an editor such as Notepad2 which displays line ending characters. This sometimes occurs if a file has been edited in Microsoft Excel and "soft returns" have been inserted.

 

By definition, a new line or line feed character signifies the end of a line, and of a record, in a delimited text file. So, you need to strip out any extraneous line-ending characters from any delimited (flat) data file you want to use with FusionPro.

 

Please see this post for some ways to strip out the embedded line ending characters.

 

* P.S. "PIN Number" is redundant, as is "ATM Machine."

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...