Help with code in a Control script

Hi - I am not sure what I am doing wrong. I have a template with 8 print sections (letters) and based on certain criteria in the data depends on which letter needs to print. It is really rather simple. However, I have this one condition that doesn’t seem to be working. I have tried to several different ways. Currently it looks like this,

if (record.fields[“IRAIND”]==“X” && record.fields[“ST”] !=“PR” && (record.fields[“PLAN”] != “840312” || record.fields[“PLAN”] != “845712”)){
merge.template.contexts.PRINT.sections.English.enabled = true;
}

My looks like this -

IRAIND = X
ST = MA
PLAN = 840312

My data does not meet this criteria as the PLAN is equal to 840312 so it should NOT be printing and it does. What am I missing here? I tried reversing the condition and still doesn’t work. Please help. Seems so simple.

Thank You

The section first needs to be disabled before trying to enable it using the condition.

merge.template.contexts.PRINT.sections.English.enabled = false;

If that still doesn’t work, can you paste the whole control script here?

Ok - yes - I did disable it. Here is a copy of what I have so far. I do have a couple more conditions to go but I test as I add a condition. It won’t work even if it is the only condition here.

var English = merge.template.contexts.Print.sections[“English”];
var TaftHartley = merge.template.contexts.Print.sections[“TaftHartley”];
var Plan606612 = merge.template.contexts.Print.sections[“Plan606612”];
var Plan8403 = merge.template.contexts.Print.sections[“Plan8403_8457”];
var IRA = merge.template.contexts.Print.sections[“IRA”];
var Select = merge.template.contexts.Print.sections[“IRASelect”];
var AutoRO = merge.template.contexts.Print.sections[“IRAAutoRoll”];
var VEBA = merge.template.contexts.Print.sections[“VEBA”];
var Green = merge.template.contexts.PRINT.sections[“GoGreen”];

merge.template.contexts.Print.sections.English.enabled = false;
merge.template.contexts.Print.sections.TaftHartley.enabled = false;
merge.template.contexts.Print.sections.Plan606612.enabled = false;
merge.template.contexts.Print.sections.PLAN8403_8457.enabled = false;
merge.template.contexts.Print.sections.IRA.enabled = false;
merge.template.contexts.Print.sections.IRASelect.enabled = false;
merge.template.contexts.Print.sections.IRAAutoROll.enabled = false;
merge.template.contexts.Print.sections.VEBA.enabled = false;
merge.template.contexts.PRINT.sections.GoGreen.enabled = false;

if (record.fields[“IRAIND”]==“X” && record.fields[“ST”] !=“PR” && (record.fields[“PLAN”]!= “840312” || record.fields[“PLAN”]!= “845712”)){
merge.template.contexts.PRINT.sections.English.enabled = true;
}
if (record.fields[“IRAIND”]==“T”){
merge.template.contexts.PRINT.sections.TaftHartley.enabled = true;
}
if (record.fields[“PLAN”]==“606612”){
merge.template.contexts.PRINT.sections.Plan606612.enabled = true;
}
if (record.fields[“PLAN”]==“840312” || record.fields[“PLAN”]==“845712”){
merge.template.contexts.PRINT.sections.Plan8403_8457.enabled = true;
}
if (record.fields[“IRAIND”]==“V”){
merge.template.contexts.PRINT.sections.VEBA.enabled = true;
}
if (record.fields[“PLAN”]== “800014” || record.fields[“PLAN”] >= “860001” && record.fields[“PLAN”] <=“861000”){
merge.template.contexts.PRINT.sections.IRAAutoRoll.enabled = true;
}

OK, now let’s revisit the condition based on the values provided:

IRAIND = X
ST = MA
PLAN = 840312

if (
record.fields[“IRAIND”]==“X” &&
record.fields[“ST”] !=“PR”
&&
(
record.fields[“PLAN”] != “840312”
||
record.fields[“PLAN”] != “845712”)
)

As you can see the first part record.fields[“IRAIND”]==“X” && record.fields[“ST”] !=“PR” is TRUE.

Now the second part record.fields[“PLAN”] != “840312” || record.fields[“PLAN”] != “845712” __ is also TRUE because:

record.fields[“PLAN”] != “840312” is FALSE but record.fields[“PLAN”] != “845712” __ is TRUE. So the OR comination of both gives a TRUE.

What you need is replace || with && like this:

if (
record.fields[“IRAIND”]==“X” &&
record.fields[“ST”] !=“PR”
&&
(
record.fields[“PLAN”] != “840312”
&&
record.fields[“PLAN”] != “845712”)
)

UGH!! Thank you so much. I knew it was something simple but I couldn’t figure it out. This will save me a ton of time with the rest of the conditions also. I would have had the same issue with a couple of the other ones. I wasn’t interpreting it that way. But it makes sense. I tried it and it works great !!!