Consider a 4-element dataset, sorted on the first column (data are for illustration only),
ds(1): Dist A, Biddle, Nelson, 5.14.2008, x, 0, 0, 0
ds(2): Dist B, Lehane, Hiram, 10.15.2011, 0, x, 0, 0
ds(3): Dist B, Calabassas, Raymond, 3.25.2009, 0, x, 0, 0
ds(4): Dist B, Hobson, Dorrine, 3.20.2007, 0, 0, x, 0
Suppose you have an array listing any indexes where there is a value change on the first ds column. In this case, there would be only one change (Dist A to Dist B), so there would be two elements:
aIndex[0] = 1 // first dataset element (always 1)
aIndex[1] = 2 // ds element on which the change occurs
Now let’s print the dataset as two passes of a loop, using temporary records. Each pass represents a unique value of ds column 1,
// 1. For each place in ds where a change of value occurs --
for(i = 0 ; i < aIndex.length ; i++) {
startPoint = starting ds element;
endPoint = ending ds element;
// 2. Step through the dataset rows that have the same first column --
for(j = startPoint ; j <= endPoint ; j++) {
// 3. Create a temporary print record for each relevant ds row --
fsPrintTemp.newRecord();
// 4. Populate temporary record columns with equivalent ds columns, for same row --
for(k = 1 ; k <= dsColumns) {
fsPrintTemp["column_" + k] = ds.getValue(j, k) ;
}
databaseManager.saveData(fsPrintTemp.getSelectedRecord());
}
// 5. Place the temp records in alphabetical order (ln, fn) --
fsPrintTemp.sort('column_2 asc, column_3 asc'); // this causes the print to be entirely blank
// 6. Create empty records after the ds records, for blank rows to bottom of form --
recs2 = maxRowsPerPage - (printRecs_ct % maxRowsPerPage);
if((recs2 > 0) && (recs2 < maxRowsPerPage)) {
for(j = 1 ; j <= recs2 ; j++) {
fsPrintTemp.newRecord(false);
databaseManager.saveData(fsPrintTemp.getSelectedRecord());
}
}
// 7. Print table and then delete all temporary records --
forms.printFormName.controller.print(false,true);
fsPrintTemp.deleteAllRecords();
}
If I only allow one pass of the outer loop, and I do not sort the temporary records, then I almost get a report – it has the correct records listed (please see attached). They just are not in the correct row locations.
If I allow more than one pass, so that controller.print() runs more than once, the results are as neatly organized as tea leaves at the bottom of a cup. Instead of two pages, there are multiple pages, and repeats of the ds values scattered throughout.
If I sort, even on one pass (which I need to do so that the temporary records can be numbered properly), I get a blank result.
Does controller.print not work if called more than once in a method?
How can I read these tea leaves?
Thank you,
Don