Menu Close

Adding custom text fields to tickets in osTicket 1.7ST

So you want to add a custom text field to your tickets in osTicket version 1.7ST? Here are instructions on what the steps are and how to do so:

Summary:

  • 1. Modify the database.
  • 2. modify shared files.
  • 3. Modify the client side.
  • 4. Modify the Staff side.

Step 1 – Modifying the Database

First you have to decide on what you would like to call your field. You should probably name this something that makes sense to the value that going to be housed in the field. Since the person that asked me to write up these instructions want to utilize a “Order Number” field that is what this tutorial is going to be written for, how ever you could just as easily use “Company Name” or “Serial No.” Once you’ve decided what your field is going to hold change it to all lowercase, Capitalizing the first later of words after the first, and remove the spaces. So “Order Number” will become “orderNumber”. If you plan on using a different field simply replace all instances of orderNumber below with your field name.

There are several ways to modify a SQL table (command line, phpmyadmin, MySQL Admin, MySQL Workbench, Navicat Lite, etc) so please feel free to use the way that you are most comfortable with. You will want to run the following SQL query:

ALTER TABLE `DATABASENAME`.`ost_ticket` ADD COLUMN `orderNumber` VARCHAR(255) AFTER `updated`;

Note: You can of course change the VARCHAR(255) to a different size [like (50)] if you plan on having a smaller value in the field.

Step 2 – Modifying the shared files

Next we will be performing a number of edits to different files in the OSTicket directory tree.

edit /include/class.mailfetch.php
in function createTicket($mid)
at line 382 add:

$vars['orderNumber']="WEB"; // set default orderNumber from emails

note: this should probably be changed to something better than “WEB”, but it will at least populate the field with something since tickets opened via email do not have an orderNumber.

Edit /include/class.ticket.php
line 87 add

$this->orderNumber     = $this->ht['orderNumber'];

line 177 add

    function getOrderNumber() {
        return $this->ht['orderNumber'];
    }

at about line 294
locate function getUpdateInfo()
in the info=array after email add

'agency' => $this->getOrderNumber(),

line 1601
add on line after $fields[’email’]

  $fields['orderNumber']    = array('type'=>'string',    'required'=>1, 'error'=>'Order Number required');

Note: you can change required from 1 to 0 if depending on if you want it required or not.

line 1644
remove ; from end of line

line 1645
add

  .' ,orderNumber='.db_input($vars['orderNumber']);

line 1864
add

  $fields['orderNumber']    = array('type'=>'string',    'required'=>1, 'error'=>'Order Number required');

Note: you can change required from 1 to 0 if depending on if you want it required or not.

at line 1970
remove the ; from the end of the line, and add the following on the next line:

.' ,orderNumber='.db_input($vars['orderNumber']);

Step 3 – Modifying the Client Side

Edit /include/client/open.inc.php
at line 45 insert the following:

<!-- start orderNumber -->
    <tr>
         <th>Order Number:</th>
         <td>
             <input id="orderNumber" type="text" name="orderNumber" size="17" value="<?php echo $info['orderNumber']; ?>">
             <font class="error">*&nbsp;<?php echo $errors['orderNumber']; ?></font>
         </td>
    </tr>
<!-- end orderNumber -->

edit /include/client/view.inc.php
add a new blank line at the end of line 35
at line 36 add:

<tr>
  <th> </th>
  <td> </td>
</tr>

on line 52 add:

<tr>
  <th width="100">Order Number:</th>
  <td><?php echo Format::htmlchars($ticket->getOrderNumber()); ?></td>
</tr>

Step 4 – Modifying the Staff Side

edit /include/staff/ticket-edit.inc.php
at line 40 (after the close tr from email)
add the following:

<tr>
  <td align="left">Order Number:</td>
  <td>
    <input type="text" size="50" name="orderNumber" value="<?php echo $info['orderNumber']; ?>">
    &nbsp;<span class="error">*&nbsp;<?php echo $errors['orderNumber']; ?></span>
  </td>			
</tr>

edit /include/staff/ticket-open.inc.php
at line 38 add:

<tr>
  <td width="160" class="required">Order Number</td>
  <td>
    <input type="text" size="50" name="orderNumber" id="orderNumber" value="<?php echo $info['orderNumber']; ?>">
    ∓nbs;<span class="error">*&nbsp;<?php echo $errors['orderNumber']; ?></span>
  </td>
</tr>

edit /include/staff/ticket-view.inc.php

at line 142 add:

<tr>
  <th> </th>
  <td> </td>
</tr>

at line 181 add:

<tr>
  <th width="100">Order Number: </th>
  <td>
    <?php echo Format::htmlchars($ticket->getOrderNumber()); ?>
  </td>
</tr>