Need help created control script that contain three main print sections with multiple letters id in each print section.

For example the main print abc, def, ghi.

Inside abc print there are abcnonbk, abcactbk, abcpriorbk, abcprose(added conditions)

Def=defnonbk, defactbk, defpriorbk,defprose

Ghi= ghinonbk, ghiactbk, ghipriorbk,ghiprose

This is what I have created but is give me error.

var lettertype = record.fields.LetterNumber;

if (lettertype == ‘abcnonbk, abcactbk, abcpriorbk, abcprose’){

merge.template.contexts.PRINT.sections['def, ghi'].enabled = __false__;

}

else if(lettertype == ’ defnonbk, defactbk, defpriorbk,defprose '){

merge.template.contexts.PRINT.sections['abc,ghi'].enabled = __false__;

}

else if(lettertype == ’ ghinonbk, ghiactbk, ghipriorbk,ghiprose '){

merge.template.contexts.PRINT.sections['abc,def'].enabled = __false__;

}

Hello katie,

You could have, of course, arrays defining which section is enabled for each type of letter. However, there is a much easier way to do this - simply using the first 3 characters of the LetterNumber field.

Here’s some code that should work for you:

// Resets all sections to disabled.
var printSections = merge.template.contexts.PRINT.sections;
for (var i = 0; i < printSections.length; i++) {
    var section = printSections[i];
    section.enabled = false;
}

// Gets the first 3 letters of the record field
var templateType = record.fields.LetterNumber.slice(0,3);

// Activate this particular template
merge.template.contexts.PRINT.sections[templateType].enabled = true;

This code is pretty optimized and will expand very easily - all you need to do is make sure that new sections are called, exactly, with the first 3 letters of the contents of LetterNumber.

Obviously my example is built upon the pseudocode you showed here - if the actual section names are not just the first 3 characters, or have variable length and such is could be more complex. But this is the gist of it.

Regards,

~Evie