OL Learn

Modify elements of a clone?

Hi,
I need to generate 2 copies of my document composed by 2 or more sections, according to an indicator field value.
So I created a control script that clone my section and it works perfect:
var printSections = merge.template.contexts.PRINT.sections;

if (record.fields.IND_ESPION && record.fields.IND_ESPION == “O”) {
//dupliquer les docs
var cloneNum = 2; //or record.fields.Counter;

for( var i = 0; i < cloneNum; i++){	
	var clone1 = printSections["Recto"].clone();			
    clone1.name = "Recto_ESP" + i;
    printSections["Verso"].addAfter(clone1);
    logger.info("Control Script IND_ESP dup fac SECTION: "+ clone1.name); 	    
    		
	var clone2 = printSections["Verso"].clone();
    clone2.name = "Verso_ESP" + i;
    printSections["Verso"].addAfter(clone2);	
}		

}

But, I need to put an other adress in clone 1 and another one in clone2 in my @ADR_CLI@ field:

@ADR_CLI@

The question is how to access the cloned sections of my PRINT context in the post pagination script?
I have tried in vain by many ways.

By post script, the merge.template.contexts.PRINT.sections result list doesn’t contain my “Recto_ESP0” and “Recto_ESP1” sections.

var adrClone = [‘XXXX
SERVICE FACTURATION
26, RUE VAN HENDE
59000 LILLE’,
‘YYYYY
SERVICE EXPLOITATION
55 BD DES ACIÉRIES
13010 MARSEILLE’];
var printSections = merge.template.contexts.PRINT.sections;
printSections[“Recto_ESP0”].find(’#ADR_CLI’).html(adrClone[0]);
It seems like the script can’t find the printSections[“Recto_ESP0”] section.

The next query returns only 1 result:
merge.context.query("#ADR_CLI").each(function(index) {
var pageName = this.info().section.name;
//logger.info("Post Pagination --------- @ADR_CLI@: "+ pageName+ ", html = " + adrClone[index]);
if(pageName==“Recto_ESP” + index){
this.html(adrClone[index]);
//logger.info("Post Pagination ----------@ADR_CLI@: "+ pageName + ", html = " + adrClone[index]);
}

	});

I have also tried by putting 3 adresses in my template:

@ADR_CLI@
@ADR_CLI_ESP1@
@ADR_CLI_ESP0@
and showing only one according to the printed section but the result is that all printed documents have the same modified adress (adrClone[0]) [section='Recto_ESP1'] .div_ADR_CLI_ESP1 { display: block; } [section='Recto_ESP1'] .div_ADR_CLI { display: none; } [section='Recto_ESP1'] .div_ADR_CLI_ESP0 { display: none; } [section='Recto_ESP0'] .div_ADR_CLI_ESP1 { display: none; } [section='Recto_ESP0'] .div_ADR_CLI { display: none; } [section='Recto_ESP0'] .div_ADR_CLI_ESP0 { display: block; } [section='Recto'] .div_ADR_CLI_ESP1 { display: none; } [section='Recto'] .div_ADR_CLI_ESP0 { display: none; } [section='Recto'] .div_ADR_CLI { display: block; }

and the result WAS …

I found this strange bahaviour:
Combining the 3 adresses in template / css file and having a post-script doing NOTHING, it works. So I can’t figure me why it works but as it works…

working with Version 2019.2.0.61422