In my control script, I would duplicate a section via clone()
var printSections = merge.template.contexts.PRINT.sections;
var numClones = record.tables[‘Notices’].length;
for ( var i = 1; i < numClones; i++){
var clone = printSections[“Section 1”].clone();
clone.name = "Section " + i;
printSections[“Section 1”].addAfter(clone);
}
Inside the loop I want to be able to pass the “i” variable so that in my Standard Script
I can refer to it?
I know I can get the section name and somehow parse the index. But I want to be able to do something like this in my standard script:
var field, result = “”;
results.html( merge.section.THE_INDEX_VALUE);
You cannot use an index number to address a section, merge.section.index isn’t valid syntax at all.
What you’re trying to do? Getting the content of a section?
This is very late reply as I have not worked on connect in a while.
The gist of what Im trying to do was. I have 1 recipient that will receive 2 rate notices(bills). The number of rate notices is based of the number of the data table’s length. The data in the notice is contained within that table. So I was duplicating the first notice so I can create the second notice.
I was under the impression once I cloned the section, the standard script will run and knowing the cloned section index , I can use it to refer to the table index and refer to the correct data and render.
PS: Though this may not be the way to go about this as I was doing aggregation of records based of the address. For eg if there are multiple records in the data with same exact address, this will be one recipient and I want to generate those pages. I thought this may be the way I can see it working as I will also have barcodes and page numbers in each of the pages.
I agree that having to parse the clone name feels awkward and it seems perfectly reasonable to try and assign the index to a custom property of the clone. Unfortunately that will not work in Connect; template objects like sections (even cloned sections) are not extensible.
You could maintain a separate object that can map a clone name to arbitrary info (like an index):
var clones = {}; // before the loop in your control script
clones[clone.name] = { index: i }; // inside the loop in your control script
results.html(clones[merge.section.name].index); // in your standard script
Of course this would error out if merge.section is not a clone. I assume you are disabling the original section.
That is interesting! I didnt know you can do that? I would definitely give that a go as I could just validate the existence of the index, maybe via
if("index" in clones[merge.section.name]){
...
}
How its working in my head is , I have one print section (original/main) that has all the variable renders , rules etc . And every iteration of a record, the control script would trigger. Then depending on the data table length if let say there’s is 2, that means I have 2 mail pieces, so I want to clone the main section, and by passing the index of the cloned section let say 1.
The cloned section would use this index to grab the correct data from the table which is table[index].firstname for eg.