Have you ever wanted to merge one ticket to another in osTicket System? Well, here is the solution to implement it. I have successfully created the modification by adding a Merge Ticket tab on the bottom of the viewticket page in admin panel. This feature can only be accessed by user with admin and manager level. After merge a ticket to another, then the original ticket status will set to closed and that tab will be disappeared. You can now merge ticket as many as you want. This modification I created based on the similar modification in osTicket Discussion Forum, but with some enhancement I added to it. Click here to see the Merge Ticket scenario I created, and also click on here to see the progress of this feature.
-
Open your \include\staff\viewticket.inc.php file, and find this code:
466 467 468 469 470 471 472 473 474 475
<div style="margin-left: 50px; margin-top: 5px; margin-bottom: 10px;border: 0px;" align="left"> <input class="button" type='submit' value='Assign' /> <input class="button" type='reset' value='Reset' /> <input class="button" type='button' value='Cancel' onClick="history.go(-1)" /> </div> </p> </form> </p> </div> <?}?>after the last line of that code, please insert this following code:
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
<? //Admin and Manager function - merge tickets. if( ($thisuser->isadmin() || $thisuser->isManager() ) && ($ticket->getStatus()!='closed') ) { ?> <div id="mergeticket" class="tabbertab" align="left"> <h2>Merge Ticket</h2> <? $sql = 'SELECT ticket_id, concat(ticketid,": ",subject) AS label FROM '.TICKET_TABLE.' WHERE email='. '(SELECT email FROM ost_ticket WHERE ticket_id = '.$id.') AND status '. '= "open" AND ticket_id <> '.$id.' ORDER BY `created` DESC '; $lookuptickets = db_query($sql); if (db_num_rows($lookuptickets)) { ?> <p> <form action="tickets.php?id=<?=$id?>#mergeticket" name="notes" method="post" enctype="multipart/form-data"> <input type="hidden" name="ticket_id" value="<?=$id?>"> <input type="hidden" name="a" value="mergeticket"> <input type="hidden" name="email" value="<?php echo $ticket->getEmail(); ?>"> <input type="hidden" name="status" value="<?php echo $ticket->getStatus(); ?>"> Merge this current ticket into ticket # <select id="keepticket" name="keepticket"> <?php while (list($ticket_id,$label) = db_fetch_row($lookuptickets)){ ?> <option value="<?=$ticket_id?>"><?=$label?></option> <? }?> </select> <div><input type="checkbox" value="1" name="notifycustomer" checked="true" />Send Email to Customer inform the Ticket Merging</div> <div style="margin-left: 50px; margin-top: 5px; margin-bottom: 10px;border: 0px;" align="left"> <input class="button" type='submit' value='Merge Ticket'/> <input class="button" type='reset' value='Reset' /> <input class="button" type='button' value='Cancel' onClick="history.go(-1)" /> </div> <?php } else { echo "Sorry, this ticket cannot be merged into another since there is no ticket has the same email address with this."; } ?> </p> </form> </p> </div> <?}?>
-
Open your \scp\tickets.php file, and find this code:
162
case 'assign':
before that line, please insert this following code:
161 162 163 164 165 166 167 168 169 170 171
case 'mergeticket': if( $ticket->mergeTicket($_POST['keepticket'], $_POST['notifycustomer'], $_POST['email'], $_POST['status'] )){ $title='Merged Tickets'; $msg='Ticket Has Been Sucessfully Merged.'; }else{ $errors['err']=$errors['err']?$errors['err']:'Unable to merge tickets or the ticket has been closed.'; } break;
-
Open your \include\class.ticket.php file, and find this code:
934 935
//online based attached files. function uploadAttachment($file,$refid,$type){
before the first line of that code, please insert this following code:
933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022
//merge this ticket to another ticket function mergeTicket($keepticket,$notifycustomer,$email,$status) { global $cfg; global $thisuser; // update these tables...: // ost_ticket_attachment $sql1= 'UPDATE '.TICKET_ATTACHMENT_TABLE.' SET '. ' ticket_id='.db_input(Format::striptags($keepticket)). ' WHERE '. 'ticket_id='.db_input($this->getId()); // ost_ticket_message $sql2= 'UPDATE '.TICKET_MESSAGE_TABLE.' SET '. ' ticket_id='.db_input(Format::striptags($keepticket)). ' WHERE '. 'ticket_id='.db_input($this->getId()); // ost_ticket_note $sql3= 'UPDATE '.TICKET_NOTE_TABLE.' SET '. ' ticket_id='.db_input(Format::striptags($keepticket)). ' WHERE '. 'ticket_id='.db_input($this->getId()); // ost_ticket_response $sql4= 'UPDATE '.TICKET_RESPONSE_TABLE.' SET '. ' ticket_id='.db_input(Format::striptags($keepticket)). ' WHERE '. 'ticket_id='.db_input($this->getId()); // create message on this ticket about merge (ost_ticket_message) $sql5= 'INSERT INTO '.TICKET_MESSAGE_TABLE.' SET '. ' ticket_id='.db_input($this->getId()). ', source="Web"'. ', created=NOW()'. ', message=CONCAT("Merged with ticket ",'. ' ( SELECT ticketID FROM '.TICKET_TABLE.' WHERE ticket_id='.db_input(Format::striptags($keepticket)).' ))'. ';'; // close and unassign this ticket (ost_ticket) $sql6 = 'UPDATE '.TICKET_TABLE.' SET '. ' staff_id = 0'. ', status = "closed"'. ', updated=NOW()'. ', closed=NOW()'. ' WHERE '. 'ticket_id='.db_input($this->getId()); if((db_query($sql1)) && (db_query($sql2)) && (db_query($sql3)) && (db_query($sql4)) && (db_query($sql6)) ){ if ( db_query($sql5) && $msgid=db_insert_id() ); { // && $msgid=db_insert_id($res5) $sql7= 'INSERT INTO '.TICKET_RESPONSE_TABLE.' SET '. ' msg_id='.db_input($msgid). ', ticket_id='.db_input($this->getId()). ', staff_id='.db_input($thisuser->getId()). ', staff_name='.db_input($thisuser->getName()). ', ip_address=""'. ', created=NOW()'. ', response=CONCAT("Ticket closed for merging reason ",'. ' ( SELECT ticketID FROM '.TICKET_TABLE.' WHERE ticket_id='.db_input(Format::striptags($keepticket)).' ))'. ';'; db_query($sql7); $sqlt = 'SELECT ticketID FROM '.TICKET_TABLE.' WHERE ticket_id='.db_input(Format::striptags($keepticket)); $rest=db_query($sqlt); if($rest && db_num_rows($rest)) list($ticketID)=db_fetch_row($rest); $sqlm = 'SELECT m.msg_id FROM '.TICKET_MESSAGE_TABLE.' m, '.TICKET_TABLE.' t WHERE t.ticketID='.$ticketID.' AND m.ticket_id=t.ticket_id ORDER BY msg_id ASC LIMIT 1'; $resm=db_query($sqlm); if($resm && db_num_rows($resm)) list($msgid)=db_fetch_row($resm); $sql8= 'INSERT INTO '.TICKET_RESPONSE_TABLE.' SET '. ' msg_id='.db_input($msgid). ', ticket_id='.db_input(Format::striptags($keepticket)). ', staff_id='.db_input($thisuser->getId()). ', staff_name='.db_input($thisuser->getName()). ', ip_address=""'. ', created=NOW()'. ', response=CONCAT("Ticket merged from ticket ",'.$this->getExtId().')'; db_query($sql8); } if ($notifycustomer && ($status!='closed')) { $helpdesk_email=$cfg->getDefaultEmail(); $helpdesk_email->send($email, 'Merging Ticket #'.$this->getExtId().' to Ticket #'.$ticketID, 'Your ticket #'.$this->getExtId().' has been merged to ticket #'.$ticketID.'.'); } return true; } else { return false; } }
Enjoy the result, everyone!

Does this code work with 1.6ST?
ps. thanks for all the code masino sinaga, your posts have been of great help.
Yes, it also works fine in 1.6 ST. I have tried it and everything seems okay.
I would like to modify this following code:
to be automated.
Example: the user would receive the following email…
Hi Tom,
Your suggestion actually has already been there. There is a checkbox item which has the label “Send Email to Customer inform the Ticket Merging” nearby the “Merge Ticket” button (see the modification step number one above).
If you have given tick mark at this item, then system will automatically send email to the related customer/client as soon as the tickets have been already merged.
As you can see at the modification step number three above, the following code will send the email to customer:
Of course you may modify the information that sent via email by yourself. Does it make sense for you?
Yes, I understand. What I am looking for is for your mod to create the clickable hyperlink to the NEW ticket automatically in the email that the user would receive.
Also, how would I create a blank line in the email? I tried with no success.
thanks and what an AWESOME mod you have here!!!
Hey,
Nice tweak.
When i tried this on the final 1.6 version, it did not work.
I am unable to see any ticket ids in the dropdown list
Please help as soon as possible
Thanks for your help
Kind Regards,
Arihant
In order to see ticket ids in the dropdown list, then you have to make sure that the current ticket you are viewing has the same email address with the email address that belongs to the destination ticket that listed in the dropdown list you want to merge into it. This is the main rule how you are able to merge a ticket into another.
I had the same problem as the guy from the 24th, no ticket numbers being shown. Can we update? Thanks a lot!
Please see my comment above. Hopefully that will help you now.
I have the same problem, no ticket ID’s are being found when I want to merge?
Any one????
You should have no problem right now if you see my comment above.
Ahhhhh I see, but this is also the way two tickets are being created, I sent one customer a ticket and he/she replies to the ticket with the ticket number untouched but from a different email adres.
The system creates a different ticket number. So now there is no way to merge??
Also I am using the latest version of osticket wich is 1.6 ST
Simply edit the email address that belongs to the second ticket, then merge it into the first one.
Mmmmm maybe If I change the email adres in the ticket by editing the ticket, this could be working?
What would be the ticket number, if I merge Ticket numer 2 with ticket number 1
Would the new created ticket be number 1?
Of course, the ticket number that will be used is the ticket number that you choose in the dropdown list (destination ticket number). Yes, in your example, the ticket number 1 will be used.
I have found my own answers, yes it works, you can change the email adres in the newly created ticket.
Than if you merge ticket number 1 with ticket number 2 (this is the last ticket) than the new ticket would be ticket number 2
Off course this would be the best solution, if you want to merge two different email addresses, the list of the ticket numbers you need to choose from would be hugh.
Thank you for this Feature!!!
Glad to hear you have found the answers by yourself. Thanks for letting us know.
Can this be changed so it does not have to be an admin account to merge tickets?
Besides admin, manager also has the ability to merge the tickets as you can see from the code at the first step above around line 480:
Of course you may modify that code in order to suits with your needs, for example by adding the ability for staff also. Hope it helps!
Table ‘db388444217.ost_ticket’ doesn’t exist
I get this error. Any advice?
It seems you did not use the default ost_ticket (default name) table. It seems you are using another name (sfs_ticket). Please change/replace the “ost_ticket” with “sfs_ticket” in that SQL.
Could this be changed to merge on open tickets and subject? instead of email?
At the moment, no!