Hi Marten,
Thanks for getting back to me, I’ve had some help from someone more efficient in JavaScript and managed to fix it so the if the detail ‘ProductName’ and ‘ProductSKU’ match the Print Context selection, turn on.
The Control script is:
var printSections = merge.template.contexts.PRINT.sections;
var itemSKUandName = record.tables.detail[0].fields.ProductSKU + ’ - ’ + record.tables.detail[0].fields.ProductName;
for (var a = 0; a < printSections.length; a++) {
var section = printSections[a];
section.enabled = false;
}
for (var jbt = 0; jbt < record.tables.detail.length; jbt++) {
for (var i = 0; i < printSections.length; i++) {
var currentsection = printSections[i];
pdn = record.tables.detail[jbt].fields.ProductSKU + ' - ' + record.tables.detail[jbt].fields.ProductName;
csn = currentsection.name;
if( pdn == csn ) {
currentsection.enabled = true;
}
}
}
The second part of the job is to Clone (duplicate) the page by the ‘Quantity’ value in the detail table for the Item. The below script was taken from a past Forum response which I’ve tried:
var ps = merge.context.sections;
for (var a = 0; a < record.tables.detail.length; a++){
for (z = 0; z < ps.length; z++ ){
if ( record.tables.detail[a].fields.ProductSKU + " - "+ record.tables.detail[a].fields.ProductName == ps[z].name){
var quantity = record.tables.detail[a].fields.Quantity;
for ( d = 0; d < quantity; d++){
results.parent().append(results.clone());
}
}
}
}
But this doesn’t give the correct number of pages. Could you let me know if you can see any issues with the above script. Or if you have any suggestions to Clone Pages on detail table values.
Thanks
Joe