Choose pages

What is the most efficient way to set up a workflow when you have a Design document that includes several pages or a page per Section but you only like to compose 2-3 pages in the workflow depending on data input.

It’s important that it should be easy to maintain, add new pages/Sections or make changes in the design of the document.

I had a similar task at time ago, but in that case the input data did not contain which pages should be printed then a used a control script lite this one to be able to control which pages should be printed.

Using a control Script like this one in the Desinger and Set jobs and info and variables in the workflow does not be the best way to solve the workflow when I have the data what pages should be printed.

if (record.fields.Invoice == ‘1’) {
printSections[‘Section 1’].enabled = true;
printSections[‘Section 2’].enabled = false;
printSections[‘Section 3’].enabled = false;
printSections[‘Section 4’].enabled = false;
printSections[‘Section 5’].enabled = false;
printSections[‘Section 6’].enabled = false;

}

else if (record.fields.Invoice == ‘2’){
printSections[‘Section 1’].enabled = false;
printSections[‘Section 2’].enabled = true;
printSections[‘Section 3’].enabled = false;
printSections[‘Section 4’].enabled = false;
printSections[‘Section 5’].enabled = false;
printSections[‘Section 6’].enabled = false;

/Thomas

If you have data which decides which sections to print, you could try something like:

var record.fields.enabled_sections = 'Section 1|Section 3|Section 4';
var enabled_sections_list = record.fields.enabled_sections.split('|');
var printSections = merge.template.contexts.PRINT.sections;
for (var i = 0; i < printSections.length; i++) {
    var section = printSections[i];
    var enabled = enabled_sections_list.indexOf(section.name) != -1;
    section.enabled = enabled;
}

this way you should be able to control the sections per record without worrying about new sections

Using Thomas’ own sample code, I think we can simplify the code (and make it fully generic) like so:

for(var i=1;i<=merge.template.contexts.PRINT.sections.length;i++){

   merge.template.contexts.PRINT.sections['Section '+i].enabled = (i===records.fields.Invoice);

}

Hi Phil,

I do get an error “printSection not defined”

The input data has columns ID, ID2 and ID3, for each record the data in those columns determin which Sections should be used.
Input data could look like this, not all records has 3 pages
Name;ID;ID2;ID3
Steven;2;4;5
Frank;1;;4
Whould it be easiest to name each Sections so it correspond to the input data, and use a control script
/Thomas

Sorry, I made a mistake while copy/pasting the code. But it wouldn’t have worked anyway, given the new information you just posted. So if I understand correctly, using your sample data, Steve would get a document with Sections 2, 4 and 5 while Frank would only get Sections 1 and 4.

If that’s correct, then the code would look something like this:

var pSections = merge.template.contexts.PRINT.sections;
for(var i=1;i<=pSections.length;i++){
pSections['Section '+i].enabled = 
   (
          (i==record.fields.ID) ||
          (i==record.fields.ID2)||
          (i==record.fields.ID3)
   );
}

?The code assumes your sections are named “Section 1”, “Section 2”, etc. The code loops through all sections and checks if the number of each section is found in any of the ID, ID1 and ID2 fields. If it is, the corresponding section is enabled otherwise it is turned off.

Thanks it worked well,
I made an adjustment

from records.fields.ID to record.fields.ID

/Thomas

Thanks for that, I adjusted my last post for future generations!