Hi,
I have already built Print Template with 2 print duplex section (4 pages document) . On my data mapper, 1 customer (HEADER) can have 1 or more table DETAIL records. Basically, I have to use 1 detail record to 4 pages document. How I can reference the same table INDEX in the script to multiple pages?
Thanks
I don’t know the structure of your data, but why not just adding this detail record to each page, e.g. in a Text Script:
var field, result = “”;
field = record.tables[“detail”][1].fields[“COLUMN2”];
if (field !== “”) result += field;
results.html(result);
which would take second record (index 1) of detail table “detail” and printing record field “COLUMN2”.
Thanks for your reply Martin
Record index is dynamic and I cannot hard coded
My data mapper looks similar below
Customer 1 (Name and Address)
Record Detail 1 (Transaction Number, amount, etc)
Record Detail 2 (Transaction Number, amount, etc)
Record Detail 3 (Transaction Number, amount, etc)
Customer 2 (Name and Address)
Record Detail 1 (Transaction Number, amount, etc)
Customer 3 (Name and Address)
Record Detail 1 (Transaction Number, amount, etc)
Record Detail 2 (Transaction Number, amount, etc)
For each Record Detail above, on my print template, I have to produce 4 pages document (with 2 print section duplex). So customer 1 will get 12 pages, customer 2 has 4 pages and customer 3 with 8 pages.
I think that needs a lot more of scripting as the order to print pages and record table details is beyond the standard behaviour.
You need to loop through all detail records in a script and for each record cloning the two sections and print the current detail record on that cloned sections, then go ahead to the next detail in the loop, cloning again, and so on. Doable but quite tricky.
So you want one or more print sections to output once per detail record?
https://learn.objectiflune.com/qa-blobs/15172853412602083930.ol-package
Too complex to describe here, but please take a look at the attached package.
1 Like
Hi, is this script still available somewhere? The link doesn’t work, and I think this solves my problem.
TDGreer
September 20, 2019, 5:28pm
7
Here’s what I have. Note, I have English and Spanish snippets, and so my code reflects that condition.
Also, this template prints Duplex, so I have snippets for the Front and Back, too (total of 4 snippets).
My Print Section contains only this:
<div id="htmlGoesHere"></div>
Control Script:
var html = '';
for(var x=0; x <= record.tables.detail.length-1; x++)
{
var frontTable = '';
var backTable = '';
if(record.fields.Country == 'US')
{ frontTable = loadhtml('snippets/FRONT_ENGLISH.html','#frontEnglishTable');
backTable = loadhtml('snippets/BACK_ENGLISH.html', '#backEnglishTable');
}
else
{ frontTable = loadhtml('snippets/FRONT_SPANISH.html','#frontSpanishTable');
backTable = loadhtml('snippets/BACK_SPANISH.html', '#backSpanishTable');
}
replacePlaceHolders(frontTable, x);
replacePlaceHolders(backTable,x);
if(x == record.tables.detail.length-1) {
query('#backEnglishTable',backTable).removeClass('tableBreak');
query('#backSpanishTable',backTable).removeClass('tableBreak');
}
html += frontTable + backTable;
}
results.replaceWith(html);
function replacePlaceHolders(theTable,index){
theTable.find('@N2@').html(record.tables.detail[index].fields.Number2);
theTable.find('@D3@').html(record.tables.detail[index].fields.Description);
theTable.find('@U4@').html(record.tables.detail[index].fields.UnitPrice);
theTable.find('@O5@').html(record.tables.detail[index].fields.Ordered);
theTable.find('@S6@').html(record.tables.detail[index].fields.Shipped);
theTable.find('@B7@').html(record.tables.detail[index].fields.BackOrder);
theTable.find('@T8@').html(record.tables.detail[index].fields.Total2);
}
Lastly, here’s one of the snippets to let you see how it all works together:
<table id="frontEnglishTable" class="table-list-blue tableBreak" data-column-resize="" data-detail="detail" title="detail">
<tbody id="getBody">
<tr data-repeat="">
<td style="width: 100%;">
<p>
FRONT- ENGLISH<br>
</p>
<p>
@N2@<br>
@D3@<br>
@U4@<br>
@O5@<br>
@S6@<br>
@B7@<br>
@T8@ <br>
</p>
<p>
<br>
</p>
<p>
@Country@<br>
</p>
</td>
</tr>
</tbody>
</table>