View Single Post
  #6  
Old July 25th, 2013, 01:27 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Alphabetize a list

Are you composing your template using only the external data file? Or are you referencing the external data file's kit number to determine which beer list to pull in?

If it's the former:
OnRecordStart()
Code:
var exData = new ExternalDataFileEx("BeerListHeader.txt",','); // Initialize External Data file
var ordered = [];  //Initialize the array
var frameName = "BeerList"; // Name of the text frame you want the list to appear in

// Populate the array with columns 1-8 of your external data list
for (var i=1; i<=8; i++){
    ordered.push(exData.GetFieldValue(FusionPro.Composition.inputRecordNumber,i));
    }

// Remove blanks from the array
for (var n=0; n<ordered.length; n++){
    if (ordered[n] == "") {
        ordered.splice(n,1);
        n--;
    }
}

// Put the contents of the array in alphabetical order
// Join the contents with break tags
ordered = ordered.sort().join("<br>");

FindTextFrame(frameName).content = ordered;
If it's the latter:
New Text Rule
Code:
var exData = new ExternalDataFileEx("BeerListHeader.txt",','); // Initialize External Data file
var ordered = [];  //Initialize the array
var kitField = "Kit#"; // Name of field in data to match the kit number in the external data file

// Populate the array with columns 1-8 of your external data list
for (var i=1; i<=8; i++){
    ordered.push(exData.GetFieldValue(exData.FindRecord("Kit",Field(kitField)),i));
    }
    
// Remove blanks from the array
for (var n=0; n<ordered.length; n++){
    if (ordered[n] == "") {
        ordered.splice(n,1);
        n--;
    }
}

// Put the contents of the array in alphabetical order
// Join the contents with break tags
ordered = ordered.sort().join("<br>");

return ordered;
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote