Print Section Twice with Controle Script

Hi,

I have “section 1” and I need multiple prints of it. I’m looking for a way not to copy the section, but to clone it with controle script for multiple prints per single record. Any options?

var section01 = merge.template.contexts.PRINT.sections[“section01”];
var testclone = merge.template.contexts.PRINT.sections[“section01”].clone();

if (record.fields[“Index”] == “1”) {
section01.enabled = true;
testclone.enabled = true;
} else {
section01.enabled = false;
testclone.enabled = false;
}

Hi Filemon,

Here is a simple example to clone a section in a control script.

//clone Section 1
var clone1 = merge.context.sections[“Section 1”].clone();

//add clone if Counter field equals 1
if (record.fields.Counter == ‘1’) {
merge.context.sections[“Section 1”].addAfter(clone1);
}

Regards,

S

Thank you works as a charm!

Glad I could help.

can I expand even further?

//clone Section 1
var clone1 = merge.context.sections[“Section 1”].clone();
var clone2 = merge.context.sections[“Section 1”].clone();

//add clone if Counter field equals 1
if (record.fields.Counter == ‘1’) {
merge.context.sections[“Section 1”].addAfter(clone1);
merge.context.sections[“Section 1”].addAfter(clone2);
}

There is a much simpler way which doesn’t require much scripting and it is done in the Data Mapper (v2018.1+):

  • Add an Action step just after the Preprocessor step
  • Set the script to : record.copies=2; The value of record.copies can also be dynamic since we are setting it in JavaScript.

That’s it.

Thank you that is an very nice option. But I’m working with multiple print sections. I only want 1 section printed multiple per record, the other prints I only need once per record. That’s why I’m trying to fix it with the controle script. I’m not getting more then one clone so far, so I think I’m not expanding the right way

Yes I thought I would just add this option here just in case.

If you want one section printed multiple times per record, then you should remove the condition if (record.fields.Counter == ‘1’) for the script to execute not only in the first record but in all records…

Nice one Rod. I actually did not know of that, thanks.

Regards,

S

Thanks for the option, I can use it in other projects very helpfull. I kind of need the condition, because there might be instances in wich there is only 1 record. (Sorry for being difficult XD)

Sure you can. :slight_smile:

var printSections = merge.template.contexts.PRINT.sections;

var cloneNum = 4; //or record.fields.Counter;

for( var i = 0; i < cloneNum; i++){

var clone1 = printSections[“Section 1”].clone();

clone1.name = “my_section_clone_” + i;

printSections[“Section 1”].addAfter(clone1);

}

Sorry I took so long, was driving home from work :slight_smile:

Regards,

S

1 Like

can anyone help me out to get multiple clones by script only?

I already did. Look at my last reply to you above.

Sharne’s example above should get you started. There is also an example in the Connect Documentation here:

http://help.objectiflune.com/en/pres-connect-user-guide/2018.1/#designer/Scripting/Scripting_Dynamically_Adding_Sections.htm

If you are still having issues, please paste your script here or open a Technical Support Ticket

Thanks that is what I was looking for, works like a charm!