Hi - I am trying to create a control script to show or hide a print section based on a condition. I have done this before and basically set it up the same way. It isn’t working for me. I read the post labeled “How to set conditions to print sections” and I still can’t seem to get it to work. I have a total of seven print sections. If the count field is equal to 0 then I need to hide the print section. This is what I have. I have tried to switch it up several different ways. This is how I left it. I used if/else, I have used if equal to then enabled=false. Nothing is working. Please help.
var DB = merge.template.contexts.PRINT.sections[‘DB’];
var LO = merge.template.contexts.PRINT.sections[‘LO’];
merge.template.contexts.PRINT.sections.DB.enabled = false;
merge.template.contexts.PRINT.sections.LO.enabled = false;
if(record.tables.DB[“TranCount”] != “0”){
merge.template.contexts.PRINT.sections.DB.enabled = true;
}
if(record.tables.LO[“TranCount2”] != “0”){
merge.template.contexts.PRINT.sections.LO.enabled = true;
}
var DB = merge.template.contexts.PRINT.sections[‘DB’];
var LO = merge.template.contexts.PRINT.sections[‘LO’];
DB.enabled = false;
LO.enabled = false;
if(record.tables.DB[“TranCount”] != “0”){
DB.enabled = true;
}
if(record.tables.LO[“TranCount2”] != “0”){
LO.enabled = true;
}
Try this
hmmmm - that isn’t working either. Its odd because I have done this a few times on different reports and it works fine. I also have a fairly simple condition that should work fine and doesn’t.
Looking back at your code:
- do you have 2 RECORD tables named DB and LO?
- TranCount and TranCount2…are they defined as string or as integer (number)?
No - one table for each. I actually have eight tables. ( DB,LO,LM,AD,AP,TP,CU,AB). I originally had TranCount, TranCount2…TranCount8 as string. I tried your new code and it did not work. Then I changed all the TranCount to integers. And still didn’t work
If you switched them to integer…you also need to modify your code since now you are using integer:
if(record.tables.DB[“TranCount”] != “0”){
DB.enabled = true;
}
if(record.tables.LO[“TranCount2”] != “0”){
LO.enabled = true;
}
…for…
if(record.tables.DB[“TranCount”] != 0){
DB.enabled = true;
}
if(record.tables.LO[“TranCount2”] != 0){
LO.enabled = true;
}
It still didn’t work even after I changed the code from “0” to 0. I found another field I can look at so I changed the record field. So now I have this - The DBTrn field is Yes or No.
if(record.field.DBTrn != “No”){
DB.enabled = true;
}
if(record.fields.LOTrn != “No”){
LO.enabled = true;
}
This works. Not sure why looking at the TranCount field wasn’t working.
Thank you!!!