Control Script for Multiple Types

I need to create a control script for multiple letter ids. Below is the script that I have, and is working, for two letter ids. I’m just not sure of the syntax for more than two letter ids.

Any assistance is appreciated. Thank you! Jennifer.

// replace var Lettertype = record.fields.xxxxxxxxx; with your field name

var lettertype = record.fields.LetterNumber;

if (lettertype == ‘VA30’){ merge.template.contexts.PRINT.sections[‘VA75’].enabled = false; }

else if(lettertype == ‘VA75’){merge.template.contexts.PRINT.sections[‘VA30’].enabled = false;}

Yes, the script is correct and the output is as expected.

When letter type is VA30, print section VA75 is disabled.

Hope this helps…

Oh! I missed .disabled in the end. Alright, let me come up with the proper answer here. Be right back!

Essentially, what you need to do at this point is to disable all of the sections, other than the one which has the same name as the value of your record. The easiest way to do this is with a loop. Assuming that the value of lettertype always has a corresponding section then the following code should work perfectly:

// Start by getting a list of the current sections in the template
var printSections = merge.template.contexts.PRINT.sections;

// Loop through each of these sections
for (var i = 0; i < printSections.length; i++) {
    var section = printSections[i];
    
    // If the section's name (VA30, VA75) is equal to the field value
    if(record.fields.LetterNumber == section.name) {
        section.enabled = true;
    } else {
        section.enabled = false;
    }
}

~Evie

Here is another way, without for loops, but more typing. I think it is easier to read however.

First create a control script, needs to be the first script then disable all sections like this:
// Page_Control Script
var CurLang = record.fields.LANGUAGEPREFERENCEGRO;

//All Sections Disabled
merge.template.contexts.print.sections.ENG.enabled = false;
merge.template.contexts.print.sections.ZHO.enabled = false;
merge.template.contexts.print.sections.RUS.enabled = false;
merge.template.contexts.print.sections.SOM.enabled = false;
merge.template.contexts.print.sections.SPA.enabled = false;
merge.template.contexts.print.sections.VIE.enabled = false;

if (CurLang == "ENG") {merge.template.contexts.print.sections.ENG.enabled = true;}
if (CurLang == "RUS") {merge.template.contexts.print.sections.RUS.enabled = true;}
if (CurLang == "SOM") {merge.template.contexts.print.sections.SOM.enabled = true;}
if (CurLang == "SPA") {merge.template.contexts.print.sections.SPA.enabled = true;}
if (CurLang == "VIE") {merge.template.contexts.print.sections.VIE.enabled = true;}
if (CurLang == "ZHO") {merge.template.contexts.print.sections.ZHO.enabled = true;}