1. Kayako Download customers: we will continue to develop and support Kayako Download beyond July 2017, alongside the new Kayako for existing customers.

    Find out more.

  2. The forum you are viewing relates to Kayako Classic. If you signed up or upgraded to the new Kayako (after the 4th July 2016), the information in this thread may not apply to you. You can visit the forums for the new Kayako here.

Prevent staff from taking ownership from other staff

Discussion in 'Developing, APIs and extending' started by Dylan Stafford, Jan 22, 2014.

  1. Once again, you're awesome Gary!

    I modified it a little so it only affects the sales dept and also does not affect admins, but works perfectly.

  2. Gary McGrath

    Gary McGrath Staff Member

    You're most welcome :)

  3. Greetings again Gary!

    It seems like management always has something else to ask for... Basically, we have a lot of agents that take every opportunity to be lazy, so I have been asked to find a way to make the agents only able to see or take ownership of the oldest unassigned ticket. They get credit for the sales leads they take ownership of and sell, so people are intentionally skipping over the ones that will be a little tougher to sell and only taking the easy ones. Then these "hard sells" will sit in the ticketing system for days while the newer ones are worked.

    Is there a way to make the agents only able to see or take ownership of the oldest ticket in the queue? They only get credit for the ones that they are the owners of, so as long as they can't take ownership that is really all that matters. I realize this is a ridiculous request, and should be more of a behavioral issue that the sales managers need to correct. Nevertheless, they have asked me to check and see if it is possible...

    Thanks again Gary!!
  4. Hi Gary,

    It looks like our agents are now assigning "Unassigned" tickets to other agents, then the other agent gets in trouble if they don't take care of the lead in time. Is there any way to modify the following code you gave me to include a check so that the agent cannot assign a ticket to another agent? And if so, where would I insert it? The agents are currently able to assign "Unassigned" tickets via the Assign button that has the pop up menu afterwards. Also, I believe they can assign tickets to anyone no matter if it is Unassigned or assigned to them via the Mass Action area after they select the check box for a ticket.

     //Stop Ticket Owner Change if Already Assigned
            if ($_SWIFT_TicketObject->GetProperty('departmentid') == 11){
                $_SWIFT_StaffObject = new SWIFT_Staff(new SWIFT_DataID($_SWIFT->Staff->GetStaffID()));
            if ($_SWIFT_StaffObject->IsAdmin() != 1 && $_SWIFT_TicketObject->GetProperty('ownerstaffid') != 0 && $_POST['genownerstaffid'] != $_SWIFT_TicketObject->GetProperty('ownerstaffid')) {
                $this->UserInterface->DisplayError("Ticket Already Assigned", "You cannot change the owner of this ticket, someone else already owns it." . $_SWIFT_StaffObject->IsAdmin());
            return false;
    Thanks a ton Gary!
    Last edited: Mar 24, 2014
  5. AndrewL2704

    AndrewL2704 Member

    Hi Gary,

    We are self hosted and have employed the code above to prevent two staff members from taking the same ticket, generally we find this is working well, however we still seem to have a problem a couple of times a week where two people are able to assign to themselves by using the take button. It seems to happen when the hit is almost simultaneously. The audit log shows this...
    24 November 2015 11:03 -
    49m 31s
    Ticket owner changed from: -- Unassigned -- to: Andrew Longhurst Andrew Longhurst (Staff)
    24 November 2015 11:03 -
    49m 29s
    Ticket owner changed from: Andrew Longhurst to: Natasha Tree Natasha Tree (Staff)

    I don't suppose you may have an ideas why this happens, when I have tested two pc's alongside each other we always see the warning?
  6. Gary McGrath

    Gary McGrath Staff Member

    Hmm, that would have to be a Collison happening literally at the same time ( probably as both have the ticket open, viewing it as unassigned, and then they don't see the new update showing the new owner )

    Avoiding that issue needs a slightly smarter collision detection, that is something we are adding into our next major release, where agent updates happen in real time, ( on the screen your viewing, even if it was not you updating the ticket )

  7. Hi Gary,

    An older topic but I still have a question about it. Although the solution works beautifully, it can still be circumvented. When one person has taken the ticket, another can still use the reply or forward tab and still send an email. This way taking ownership is circumvented. Is it possible to disable the Reply and Forward tabs as long as owner isn't set?
  8. Gary McGrath

    Gary McGrath Staff Member

    It's certainly possible, but above would you not want to disable them if it is unassigned, or it is not assigned to you?

  9. Hi Gary,

    That's exactly what I want. Either disable or hide the tabs Reply & Forward when the ticket is unassigned or not assigned to you.
  10. Hi Gary,

    I've found a way to generate error when the ticket is unassigned and someone wants to forward the ticket:

    in class.Controller_Ticket.php in public function Forward
    if ($_SWIFT_TicketObject->GetProperty('ownerstaffid') == 0) {
                $this->UserInterface->DisplayError("You are not the owner of this ticket!");
                return false;
    However if someone else then the current staff member is already owner the forward tab still renders. What do I need to add to my IF statement to prevent this?

    And any help on where I can find where the Reply tab is Rendered would be greatly appreciated. I found RenderForward, but RenderReply doesn't seem to exist.
    Last edited: Jun 1, 2016
  11. Gary McGrath

    Gary McGrath Staff Member


    In here there is a function called public function RenderTicket

    within that, you will see sections of code ( it is commented ) like, begin general tab, reply tab, forward tab etc..

  12. Gary, you're an absolute hero! I changed the necessary lines from

    if ($_SWIFT->Staff->GetDepartmentPermission($_SWIFT_TicketObject->GetProperty('departmentid'), 'd_t_canreply') != '0' && $_SWIFT->Staff->GetPermission('staff_tcanreply') != '0' ) {

    if ($_SWIFT->Staff->GetDepartmentPermission($_SWIFT_TicketObject->GetProperty('departmentid'), 'd_t_canreply') != '0' && $_SWIFT->Staff->GetPermission('staff_tcanreply') != '0' && $_SWIFT_TicketObject->GetProperty('ownerstaffid') != 0 && $_SWIFT_TicketObject->GetProperty('ownerstaffid') == $_SWIFT->Staff->GetStaffID()) { 

Share This Page