Select detail record for each section clone

Hi,
we want to create cheque books by printing one cheque for each detail record.

I used following script to clone the cheque page section:

var printSections = merge.template.contexts.PRINT.sections;
var numClones = record.tables['detail'].length;
for ( var i = 0; i < numClones; i++){
var clone = printSections["chq"].clone();
clone.name = "chq" + i;
printSections["chq"].addAfter(clone);
}

And then I tried to get the field value with something like this:

results.each(function(index) {
var field, result = "";
n=  //NEED HELP to retrieve the detail record index from section name
field = record.tables["detail"][n].fields["number"];
if (field !== "") result += field;
this.text(result);
});

How can I extract the detail record index from the section name?
Is there a better way to get what I’m trying to do?

thank you!

You were already there…
n = index!

So you don’t need n, simply use index

makes sense but it doesn’t seem to work in my case.
The section clones are created in the output but all of them display the value of the first detail record

Can you show the HTML code of the section and bold the table and particulary the td holding the placeholder?

sure, I just started testing this concept so it’s pretty simple:


<div id= *"barcode"* class= *""* anchor= *"page_media_0"*

data-params= “{"textPosition":"BOTTOM","fontFamily":"Arial","backColor":"#FFFFFF","codeSet":"AUTO","showText":true,"moduleWidth":0.04,"processTilde":true,"scale":0,"fontSize":10,"barColor":"#000000","outputFormat":"SVG"}”

style="transform: *rotate(-90deg)* ; width: *263px* ; height: *71px* ; position: *absolute* ; left: *-15.0333px* ; top: *143.033px* ; text-align: *center* ;"

type= *"com.objectiflune.connect.addin.barcodes.code128"* offset-x= *"-15.0333"* offset-y= *"143.033"* >

</div>

<div class= *""* anchor= *"page_media_0"*

style="position: *absolute* ; overflow: *hidden* ; box-sizing: *border-box* ; width: *75px* ; height: *20px* ; top: *22.1px* ; left: *537px* ; text-align: *right* ;" offset-x= *"537"* offset-y= *"22.1"* >

<span class= *"type ol-scripted"* >@type@</span>

</div>

Reviewing my knowledge of clones, I realized that replacing value accross cloned section can be a little tricky.
Why don’t you read your data in the Datamapper so it generate a record for each check?
Nothing stops you to have a general section that will only print on the first record (using record.index to base your condition on).
Then have a second section that prints for every record.

yeah, I’ll try it like you suggest. It seemed neater to have one recorded per book,

thanks
Akis

1 Like