how to sequence section

How do I set sequence print section?

I have to add all section in same designer because I have to add page number every page.

EX. I have Section1, Section2 and Section3 in Designer.

Print out order

Record type A : Section1, Section2 and Section3

Record type B : Section2, Section1 and Section3

Record type C : Section3, Section2 and Section1

Record type D : Section1, Section3 and Section2

Record type E : Section1, Section3

You need to do that in a Control script.

Let me demonstrate with two sections ‘Section 1’ and ‘Section 2’ which you like to control the sequence for by field ‘Counter’ (in Designer Section 1 is the first one).
If Counter==‘2’ it should print ‘Section 2’ first, otherwise ‘Section 1’ is on top:

//cloning the sections
var clone1 = printSections[‘Section 1’].clone();
var clone2 = printSections[‘Section 2’].clone();

//adding the clones in a certain order controlled by field ‘Counter’
if (record.fields.Counter == ‘2’) {
printSections[‘Section 1’].addAfter(clone2);
printSections[‘Section 2’].addAfter(clone1);
} else {
printSections[‘Section 1’].addAfter(clone1);
printSections[‘Section 2’].addAfter(clone2);
}

//disable the orignal sections
printSections[‘Section 1’].enabled = false;
printSections[‘Section 2’].enabled = false;

Hi Marty,

In this topic from for example:

printSections[‘Section 1’].addAfter(clone1);
printSections[‘Section 1’].addAfter(clone2);
printSections[‘Section 1’].addAfter(clone3);

printSections[‘Section 1’].enabled = false;

Im cloning 3 section. What If I want to add a different section in before each one of the clone?

var letterSection = printSections[‘InBetweenSection’].clone();

printSections[‘Section 1’].addAfter(clone1);
printSections[‘Section 1’].addAfter(letterSection);

printSections[‘Section 1’].addAfter(clone2);
printSections[‘Section 1’].addAfter(letterSection);

printSections[‘Section 1’].addAfter(clone3);
printSections[‘Section 1’].addAfter(letterSection);

is it possible to do this? Cause when I do and I preview Section 1 everything goes haywire.

Any help would be appreciated
Kind regards,
E

Update: Although the preview goes bonkers, when I print it. It actually works… which is great!

Replying from my previous respond.

Update: Although the print pdf output works and actually adding a section per clone.
But when I run this through the Workflow to get the page count via api, I am suddenly getting wrong count of pages! This is frustrating.

Update: The API Actually counts for media count in array. This is my oversight. Apologize