CA Service Management

 View Only

 Restrict to create ticket

king khan's profile image
king khan posted Oct 27, 2021 06:09 AM
Dear Members

We have a requirement for one of the service request that any user should not be able to submit a new request for the specific category if 3  tickets already submitted with same category in the system & currently active status.  If the no.of Active tickets for that category is less than 3, than ca system should allow the user to submit the request.

How can we achieve this from DP or any other way?
Aleksandar Stancic's profile image
Aleksandar Stancic
You can create PRE_VALIDATE SPEL trigger to check the current number of open requests per your condition and based on that allow save of request or return appropriate error message.
king khan's profile image
king khan
Dear @Aleksandar Aleksic 

Thanks for your reply,

Im new in Spell, Can you please help to write spell​ to validate  if number of request >= 5 && status =="OP", Then Display message "not allowed" else save the ticket.

Ill  modify it according to my requirement later.
hermann1815's profile image
hermann1815
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>​
king khan's profile image
king khan
Dear Henning

Many Thanks for your input, i tried below code adding category in whereclause , and create a new request, on clicking save button, it show the alert msg everytime even there is only one OPEN (status) ticket. even if i use different category other than whereclause one, its throwing same alert msg when click on save button.

If i change the status of old/already open tickets to 'In progress' or other status, then try to create a ticket then nothing happens when click on Save button.

Can you please help, it seems we are almost there to achieve but something is missing.



<script>
<PDM_IF "$args.id" == "0">
var countcr = 0;
<PDM_LIST PREFIX=crlist FACTORY="cr" WHERE="category='pcat:3312365' 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>

hermann1815's profile image
hermann1815
If I think about it again, the implementation is difficult because you only look at the category of the current ticket and not all of them .. and that´s why i recommend to do it via spel (i`am not good at that).
Marc Horlomus's profile image
Marc Horlomus
not tested!!!! :)

zcr.mod:

MODIFY cr POST_VALIDATE zCatValidater(persistent_id) 1000 FILTER (EVENT("INSERT"));

zcr.spl:

cr::zCatValidater(...) {
   send_wait(0, top_object(), "call_attr", "cr", "sync_fetch", "STATIC", format("category='%s' and status='OP'", this.persistent_id), -1, 0);
   if(msg[1] > 4) {
      set_return_data("not allowed");
      set_error(1);
   }
}
king khan's profile image
king khan
Dear @Marc Horlomus

Many Thanks for your help.

I tried your below spell by putting pcat value & its work all good but when the number of ticket reaches upto 5 for this category with ''open'' status, then message appear "not allowed" which is OK. But other categories also restricted and shows the same message and cannot create req tickets for other categories until the status is changed from OPEN to any other.

may be little tweak required to achieve this. :)



cr::zCatValidater(...) {
   send_wait(0, top_object(), "call_attr", "cr", "sync_fetch", "STATIC", format("category='pcat:3342163' and status='OP'", this.persistent_id), -1, 0);
   if(msg[1] > 4) {
      set_return_data("not allowed");
      set_error(1);
   }
}
Marc Horlomus's profile image
Marc Horlomus
sry, my fault, should be:
send_wait(0, top_object(), "call_attr", "cr", "sync_fetch", "STATIC", format("category='%s' and status='OP'", this.category), -1, 0);
king khan's profile image
king khan
OK i have made the changes as below but where i have to specify Category value to work this spell only for that category?

send_wait(0, top_object(), "call_attr", "cr", "sync_fetch", "STATIC", format("category='%s' and status='OP'", this.category), -1, 0);
Marc Horlomus's profile image
Marc Horlomus
the %s is replaced by this.category, which is the category from the ticket in whose context the trigger is running. so, i think, this should work with all categories :)
king khan's profile image
king khan
Dear @Marc Horlomus

Many Thanks, your spell worked for me after little tweaking. :)
J