How to Customize the Ticket Number in osTicket v1.6 RC5

If you want to customize the ticket number in your osTicket System, then this modification is for you. As we know, the ticketID field in ost_ticket table has the field type as int(11). It means that this field can only contains of the numerical data. Sometimes you want to change that original ticket number from which contains of the six digits numerical data become something which contains of the alpha-numeric characters. For example, you want to add the Custom prefix which in this case contains of letters, then you have to alter that field type, for instance, become varchar(12).

  1. Alter your ost_ticket table by changing the type of ticketID field, from int(11) become varchar(12). Adjust the value: 12 with your requirement.
  2. Open your \include\class.misc.php file, and find this code:

    30
    
            return mt_rand($start,$end);

    then replace with:

    30
    
            return "Custom".mt_rand($start,$end);
  3. Open your login.php file, and find this code:

    44
    45
    
        //See if we can fetch local ticket id associated with the ID given
        if(!$errors && is_numeric($ticketID) && Validator::is_email($email) && ($tid=Ticket::getIdByExtId($ticketID))) {

    then replace with this following code:

    44
    45
    
        //See if we can fetch local ticket id associated with the ID given
        if(!$errors && Validator::is_email($email) && ($tid=Ticket::getIdByExtId($ticketID))) {
  4. Open your \include\staff\tickets.inc.php file, and find this code:

    136
    
            if(is_numeric($searchTerm)){

    then replace with this following code:

    136
    
            if($searchTerm){
  5. Open your \include\ajax.tickets.php file, and find this code:

    49
    
            if(is_numeric($input)) {

    then replace with this following code:

    49
    
            if($input) {

    Find again this code:

    71
    
            if(!$params['tid'] or !is_numeric($params['tid']))

    then replace with this following code:

    71
    
            if(!$params['tid'])

    Find again this code:

    104
    
            if(!$params['id'] or !is_numeric($params['id']))

    then replace with this following code:

    104
    
            if(!$params['id'])
  6. Open your tickets.php file, and find this code:

    if(($id=$_REQUEST['id']?$_REQUEST['id']:$_POST['ticket_id']) && is_numeric($id)) {
        //id given fetch the ticket info and check perm.
        $ticket= new Ticket(Ticket::getIdByExtId((int)$id));

    then replace with this following code:

    if(($id=$_REQUEST['id']?$_REQUEST['id']:$_POST['ticket_id']) && $id) {
        //id given fetch the ticket info and check perm.
        $ticket= new Ticket(Ticket::getIdByExtId($id));
  7. Open your /include/class.ticket.php file, and find this code:

    1226
    1227
    
                    $extId=$id; //To make things really easy we are going to use autoincrement ticket_id.
                    db_query('UPDATE '.TICKET_TABLE.' SET ticketID='.db_input($extId).' WHERE ticket_id='.$id);

    then replace with this following code:

    1226
    1227
    
                    $extId=$id; //To make things really easy we are going to use autoincrement ticket_id.
                    db_query('UPDATE '.TICKET_TABLE.' SET ticketID="Custom'.db_input($extId).'" WHERE ticket_id='.$id);

In this example, you want to add the Custom prefix into the ticket number.

Share

1,680 viewsPrint This Post Print This Post

Comments

  1. hey my friends,

    nice article, but something missing in your article:

    in include\class.ticket.php

    Line 1331 and 1332 search for:

    $extId=$id; //To make things really easy we are going to use autoincrement ticket_id.
    db_query(‘UPDATE ‘.TICKET_TABLE.’ SET ticketID=.db_input($extId).’ WHERE ticket_id=.$id);

    replace with:

    $extId=$id; //To make things really easy we are going to use autoincrement ticket_id.
    db_query(‘UPDATE ‘.TICKET_TABLE.’ SET ticketID=”Custom’.db_input($extId).’” WHERE ticket_id=.$id);
  2. @Malte Glöckner

    Thanks for the correction. I have added that missing step.
    Cheers! :-)

  3. Clive Hawkins says:

    Great article and easy to follow with thanks.

    For those that use piping for adding email replies to ticket you will have to edit the pipe.php file as follows:

    File: installdir/includes/api/pipe.php

    Lines 94 & 95 – original

    if(preg_match ("[[#][0-9]{1,10}]",$var['subject'],$regs)) {
        $extid=trim(preg_replace("/[^0-9]/", "", $regs[0]));

    Replace to:

    if(preg_match ("[[#][A-Za-z0-9-]{1,10}]",$var['subject'],$regs)) {
        $extid=trim(preg_replace("/[^A-Za-z0-9-]/", "", $regs[0]));

    At least that’s what I did and my pipe is now working a treat. If you dont change this piping doesn’t work and it just creates a new ticket when someone replies to an email response.

  4. @Clive Hawkins

    Thanks for the feedback, Clive. I appreciate it.

  5. GeorgeB says:

    it is not letting me change the ost_ticket ticketid field. It keeps saying this:

    SQL query:

    ALTER TABLE `ost_ticket` CHANGE `ticketID` `ticketID` VARCHAR( 12 ) UNSIGNED NOT NULL DEFAULT ’0′

    MySQL said: Documentation
    #1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘UNSIGNED NOT NULL DEFAULT ’0” at line 1

Speak Your Mind

*


*