Maybe it´s easier than you thought. You can use the code in your detailform (detail_cr.htmpl).
<script>
<PDM_IF "$args.id" == "0">
var countcr = 0;
<PDM_LIST PREFIX=crlist FACTORY="cr" WHERE="type='R' and status='OP'">
<PDM_IF "$crlist.id" \> "3">
countcr = 1;
</PDM_IF>
</PDM_LIST>
function preSaveTrigger() {
if (countcr == 1) {
showAlertMsg("<font color='red'><b>You can´t save the ticket, because there are more than 3 tickets open!</b></font>");
}
}
</PDM_IF>
</script>
I think it isn´t the best way to do it, but try it. Of course you have to add the category in the WHERE-Clause. It´s UNTESTED
It will fire when the user pressed the save button. But you can also check it directly on a new ticket:
<script>
<PDM_IF "$args.id" == "0">
var countcr = 0;
<PDM_LIST PREFIX=crlist FACTORY="cr" WHERE="type='R' and status='OP'">
<PDM_IF "$crlist.id" \> "3">
countcr = 1;
showAlertMsg("<font color='red'><b>You can´t save the ticket, because there are more than 3 tickets open!</b></font>");
return false;
</PDM_IF>
</PDM_LIST>