Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

osTicket v1.10 (stable) and Maintenance Release v1.9.15 are now available! Go get it now

Adding a New Field to tickets

There have been a lot of questions about how to add a new field to the ticket and rightly so, the more info a user can provide the better. For our purposes we wanted to add a Company field so we knew exactly who we were dealing with.

We added the field successfully and this thread explains the process. As a favor, can someone help us with adding that new field to the "tickets.inc.php" page?!?! It would be greatly appreciated. We'd like to be able to see Company in that table as a column where you see the ticket id, date, department, priority etc.

To add a new field there are 6 places you have to go to accomplish your goal.
[LIST=1]
[*]MySQL Database: manually add a field to ost_Ticket
[*]support/include/class.ticket.php
[*]support/include/client/open.inc.php
[*]support/include/client/viewticket.inc.php
[*]include/staff/viewticket.inc.php
[*]include/staff/newticket.inc.php
[/LIST]

2.) class.ticket.php
Add your variable here:

class Ticket{

var $id;
var $extid;
var $email;
var $status;
var $created;
var $updated;
var $priority;


and here: like so ($this->newvar=$row['newvar'];)


if(($res=db_query($sql)) && db_num_rows($res)):
$row=db_fetch_array($res);
$this->id =$row['ticket_id'];
$this->extid =$row['ticketID'];
$this->email =$row['email'];
$this->fullname =$row['name'];

and here:


//GET
function getId(){
return $this->id;
}

function getExtId(){
return $this->extid;
}

function getEmail(){
return $this->email;
}

function getNewvar(){
return $this->newvar;
}


and here:


function create($var,&$errors,$origin,$autorespond=true,$alertstaff=true) {
global $cfg,$thisclient,$_FILES;

$id=0;
$fields=array();
$fields['newvar'] = array('type'=>'string', 'required'=>1, 'error'=>'newvar required');


and finally:


$extId=Ticket::genExtRandID();
$sql= 'INSERT INTO '.TICKET_TABLE.' SET created=NOW() '.
',ticketID='.db_input($extId).
',dept_id='.db_input($deptId).
',priority_id='.db_input($priorityId).
',email='.db_input($var['email']).
',name='.db_input(Format::striptags($var['name'])).
',newvar='.db_input(Format::striptags($var['newvar'])).


3.) open.inc.php Copy info from other the other fields, just make sure the new field php scripts are different.

4.) viewticket.inc.php Repeat Step 3


5.) staff/viewticket.inc.php Repeat Step 4


6.) staff/newticket.inc.php Repeat Step 5
«13456789

Comments

  • This is a gold mine right here. Just what I was looking for!!
  • Frink09,

    This is exactly what I am looking for to add a new field for the form. I must say I am having a lot of trouble following step3 and above since I don't know exactly what to add and where in the file is a good place to add it. I broke the pages by adding stuff from step 2. Would you be able to explain what I really need to do in step 3?

    Thanks a bunch,
    G
  • My line numbers might be a little off as I have other mods but...

    class.ticket.php Step 1: approx line 27
    class.ticket.php Step 2: approx line 62
    class.ticket.php Step 3: approx line 111
    class.ticket.php Step 4: approx line 820
    class.ticket.php Step 5: approx line 913
    3.) open.inc.php Copy info from other the other fields, just make sure the new field php scripts are different.
    Say you were adding a confirm email address field, just copy:

    $fields['email']    = array('type'=>'email',    'required'=>1, 'error'=>'Valid email required');


    Paste, then change it to:

    $fields['confirm_email']    = array('type'=>'confirm_email',    'required'=>1, 'error'=>'Email addresses must match');


    I changed the elements so they would have different names.
    ***NOTE:
    the 'type' refers to the type of data on the form. confirm_email is not a default type. Here is a list of the types supported for validation by default.
    'integer':
    'int':
    'double':
    'text':
    'string':
    'array':
    'radio':
    'date':
    'time':
    'phone':
    'fax':
    'email':
    'url':
    'password':
    'username':
    'zipcode'



    Hope this helps you apply the mod.

    Also I have not followed these steps yet, I plan on adding fields later today or tomorrow. I will follow up with success or failure.
  • micro3d,

    Thanks a bunch for this. I will try it out very soon and post my outcome. Thanks again for this.
  • This was the biggest problem we had with osticket, thanks!
  • Glad to be of help. Sorry I didn't respond sooner, got distracted with other things. With the help of another user we were able to insert our Company Field as a column in the Staff Tickets area.
  • Problema al crear nuevo ticket

    Estimados,
    Segui las instrucciones paso a paso para poder agregar mas opciones al formulario (field) pero encontre un error.

    Al tratar de crear un nuevo ticket sin estar autenticado, funciona bien-
    Pero, al tratar de crear un nuevo ticket estando autenticado no se despliega la página completamente.

    He buscado en el ćodigo cual puede ser ewl problema y no pude encontrar nada.

    Alguine me puede ayudar?

    Best regards

    Saludos
    BAGG
  • Google Translation

    Estimates,
    Segui the directions step by step to add more options to form (field) but I found a mistake.

    In trying to create a new ticket without being authenticated, works well -
    But in trying to create a new ticket not be authenticated unfolds page completely.

    He looked at ćodigo which can be EWL problem and I could not find anything.

    Alguin can help me?

    I think he is saying on the client side it works fine but on the Staff Ticket creation side it is broken.

    As for a fix... I'd guess you would need to add your new fields to the staff\newticket.inc.php just the same as you did for client\open.inc.php

    Im going to make time right now to do this mod so I can actually come up with some real ideas.
  • Hi,
    status is:
    User not autenticated: good creted new ticket, not problem
    User autenticated: problem in create new ticket (show page incomplete)
    Staff: good, not problem.

    best regards.
    BAGG
  • I was able to successfully add a new field to my ticket. I tested it in the client side and the staff side(w/o mod) and it works great!

    /* Add New Fields Modification
    * Author: James Williams
    * osTicket v1.6 RC4
    * Date: 07-22-08
    * Ref: http://www.osticket.com/forums/showthread.php?t=873
    */

    DB Table: ost_ticket
    Field Type Collation Attributes Null
    location text latin1_general_ci No



    +ADD include\client\open.inc.php between subject and intersection

    <tr>
    <th valign=\"top\">Location, Address, or Intersection:</th>
    <td>
    <? if($errors['location']) {?> <font class=\"error\"><b>&nbsp;<?=$errors['location']?></b></font><br/><?}?>
    <textarea name=\"location\" cols=\"35\" rows=\"3\" wrap=\"soft\" style=\"width:85%\"><?=$info['location']?></textarea></td>
    </tr>


    +ADD include\class.ticket.php
    var $location;		// mod080722_new_ticket_field


    +ADD include\class.ticket.php
    $this->location	=$row['location'];	 // Mod080722_new_ticket_field


    +ADD include\class.ticket.php
    // mod080722_new_ticket_field
    function getLocation() {
    return $this->row['location'];
    }


    +ADD include\class.ticket.php
    $fields['location']		= array('type'=>'text',		'required'=>0, 'error'=>'Provide a location, address, or directions'); //mod080722_new_ticket_field


    +ADD include\class.ticket.php
    	//We are ready son...hold on to the rails.
    $extId=Ticket::genExtRandID();
    $sql= 'INSERT INTO '.TICKET_TABLE.' SET created=NOW() '.
    ',ticketID='.db_input($extId).
    ',dept_id='.db_input($deptId).
    ',priority_id='.db_input($priorityId).
    ',email='.db_input($var['email']).
    ',name='.db_input(Format::striptags($var['name'])).
    ',subject='.db_input(Format::striptags($var['subject'])).
    ',location='.db_input(Format::striptags($var['location'])). // mod080722_new_ticket_field
    ',phone='.db_input($var['phone']).
    ',ip_address='.db_input($ipaddress).
    ',source='.db_input($source);
  • bgalvez;3688 said:
    Hi,
    status is:
    User not autenticated: good creted new ticket, not problem
    User autenticated: problem in create new ticket (show page incomplete)
    Staff: good, not problem.

    best regards.
    BAGG
    I just tested my Mod with an Auth User. Ticket created fine. Is your new field required? Also, could you attach your class.ticket.php and open.inc.php

    Por otra parte, ¿podría adjuntar su class.ticket.php y open.inc.php (google)
  • In your open.inc.php Lines 30 to 41

    [HTML]
    Empresa:

    <?if ($thisclient && ($newvar=$thisclient->getNewvar())) {
    ?>
    "><?=$newvar?>
    <?}else {?>
    ">
    <?}?>
     * <?=$errors['newvar']?>

    [/HTML]

    Delete that temporarily. This will tell us if it is the getNewvar() function that is hold up the page. If it loads fine after this is deleted then the problem is with getting your Newvar out of your database.

    Also, $thisclient->getNewvar() isn't calling your getNewvar() function from class.ticket.php , it is calling it from class.client.php.

    After the ticket is made the company name is saved with the ticket, that is how you can view your company from the view ticket. When you are on the new ticket page, your name and email are pulled from class.client.php so you might have to create a company var in class.client.php and add a field in your DB and edit the sql on line 45

    The attached files are the files that the user sent me for me to look over. I included them for reference if anyone else is having the same problem.
    CompanyField.zip
    12K
  • Can a Wizard be created to add fields?

    Hey everyone,

    This seems like agreat product.

    But like this thread suggests, new fields are needed to be added or others need to be modified.

    I am seeking a customizable ticket system for my group at work.

    Can a wizard be created to allow the user to customize the ticket form?

    Thank you and God bless,
    Johnathan
    http://www.agodblessedman.com
  • Frink09;3304 said:
    To add a new field there are 6 places you have to go to accomplish your goal.
    [LIST=1]
    [*]MySQL Database: manually add a field to ost_Ticket
    Would anyone mind explaining the steps to add a field to a database?
  • This was a big help. Thanks
  • Does anyone have the code to add drop down menus to the new field? I simply want to add a few choices to that field. Thanks so much for the coding to add a new category. It worked like a charm.
  • exactly what i wanted but.

    Ok this is exactly what I was looking for, the ability to make custom fields on the tickets. I have spent about 4 hours of my free time and about another 4 hours at work trying to get this modification to function properly.

    I needed to add to the ticket form the field of Serial Number, I added it using the tutorial in this thread but when both the phone field and the Serial number fields are entered, the phone field appears then vanishes when you view a ticket, it does the same thing when i view the table in MySQL. Why is this? I have spent quite a bit of time moving the fields around and dropping them and putting them back up. I have also re-written all of the modifications in the php files quite a few times, and played around with the options in MySQL. What am i missing? anyone have any ideas where i should look to correct this problem?
  • blorenzo;4747 said:
    Ok this is exactly what I was looking for, the ability to make custom fields on the tickets. I have spent about 4 hours of my free time and about another 4 hours at work trying to get this modification to function properly.

    I needed to add to the ticket form the field of Serial Number, I added it using the tutorial in this thread but when both the phone field and the Serial number fields are entered, the phone field appears then vanishes when you view a ticket, it does the same thing when i view the table in MySQL. Why is this? I have spent quite a bit of time moving the fields around and dropping them and putting them back up. I have also re-written all of the modifications in the php files quite a few times, and played around with the options in MySQL. What am i missing? anyone have any ideas where i should look to correct this problem?
    I have to step out of the office atm but I will address this issue and work with you to try and get you up and going today.
  • Im back

    Can you post or email me your files? use the list at the start of the thread for which files I need.

    micro3d [AT] gmail [DOT] com

    I will give them a review and try to get back to you asap.
  • Hi, I just installed osticket and did this mod and it seems to work great. One thing I would like to do is also add the new field to the table view of tickets in the admin panel. Is that something that could be easily done?
  • resolved

    I have found the issue and resolved it. Thank you for your willingness to help.
    I think I should have no more problems adding fields. I've added a total of 3 so far. There are a few more mods I would like to make however, I shall search the forum for the answer.

    Any idea how to import emails from a csv file to the MySQL DB so when we take a service call we can begin typing their email and then their name appears?
  • oriecat;4765 said:
    Hi, I just installed osticket and did this mod and it seems to work great. One thing I would like to do is also add the new field to the table view of tickets in the admin panel. Is that something that could be easily done?
    While there isn't a "blank template" MOD for displaying new fields into the SCP Ticket View, you might be able to derive some code from the following mods that add new columns to the view. I have not inspected these in depth but would imaging that you would simply need to just change where you are pulling the data from (from your new field in the DB).

    Next to respond mod:
    http://osticket.com/forums/showthread.php?t=736&highlight=respond

    Assigned to Who:
    http://www.osticket.com/forums/showthread.php?t=1068
  • blorenzo;4771 said:
    I have found the issue and resolved it. Thank you for your willingness to help.
    I think I should have no more problems adding fields. I've added a total of 3 so far. There are a few more mods I would like to make however, I shall search the forum for the answer.

    What was the fix? It might help someone else.
    blorenzo;4771 said:
    Any idea how to import emails from a csv file to the MySQL DB so when we take a service call we can begin typing their email and then their name appears?
    Importing the contact information into the DB is easy with phpMyAdmin. I think the problem you will run into is you will need to create an AJAX script that will query that list as you change your text box.

    AJAX Live Search // Auto Complete
    http://www.w3schools.com/php/php_ajax_livesearch.asp
  • micro3d;4772 said:
    While there isn't a "blank template" MOD for displaying new fields into the SCP Ticket View, you might be able to derive some code from the following mods that add new columns to the view. I have not inspected these in depth but would imaging that you would simply need to just change where you are pulling the data from (from your new field in the DB).
    [/url]
    Thank you. I did find that thread later and was able to make the change as shown there. :)
  • Response

    The problem I ran into was actually being caused by my Skype. It did not effect computers that did not have skype installed. Basically if you have used it before it automatically detects phone numbers and converts them to links that you can call by clicking on them. Some how the serial number field I made was conflicting with the phone number field, which caused my computer to make the phone number field vanish. It was quite odd tho because it only effected the fields at certian times. And if you did not enter a phone number or serial the problem would not occure. It was a strange problem, but by repositioning the field (several times) it has gone away.
    Importing the contact information into the DB is easy with phpMyAdmin. I think the problem you will run into is you will need to create an AJAX script that will query that list as you change your text box.

    AJAX Live Search // Auto Complete
    http://www.w3schools.com/php/php_ajax_livesearch.asp

    Thanks micro3d, extremly helpfull. I will be using this to do what my bosses want.

    I have a new issue, I have been trying to add the Serial field to the ticket.php page and have succedded in creating the collum and row. However it is not pulling up the serial number information from the database. What must I modify/add to make it do so? I usually search for the other fields and copy them and make the modifications needed to make it pull the proper information. In this case I am having difficulty finding that.

    EDIT:
    I have discovered that if i enter in "name" where i have the serial var, it will pull the names into the colum but not the serial. And when i enter serial into another colum it will not pull it. This leaves me to beleive its a problem with the database. But how come on all other screens (newticket,viewticket,open) it pulls the serial number and displays it. but not on tickets.php? what am i missing??

    this is the code i am using.... and it does not work.

    <?=Format::truncate($row['serial'],22,strpos($row['serial'],'@'))?> 
    but if I enter this
    <?=Format::truncate($row['name'],22,strpos($row['serial'],'@'))?> 
    It displays names in the serial colum I made. So the code is grabbing information. And there is information because on other pages it is displaying the serial... this is driving me crazy :(
  • modded

    does n e use osticket for IT support like a computer shop, and have succesfully added fields? and will b willing to send it to me
  • micro3d,

    I followed your instructions perfectly in regards to creating a new field in the ticket system called "Domain Name or Company:"

    I edited all the mentioned files in the different locations and added the filed in my database:

    mysql> alter table hd_ticket add domain_name varchar(255) after email;
    Query OK, 51 rows affected (0.09 sec)
    Records: 51 Duplicates: 0 Warnings: 0

    mysql> show columns from hd_ticket from my_helpdesk;
    +-------------+-----------------------------+------+-----+---------------------+----------------+
    | Field | Type | Null | Key | Default | Extra |
    +-------------+-----------------------------+------+-----+---------------------+----------------+
    | ticket_id | int(11) unsigned | NO | PRI | NULL | auto_increment |
    | ticketID | int(11) unsigned | NO | MUL | 0 | |
    | dept_id | int(10) unsigned | NO | MUL | 1 | |
    | priority_id | int(10) unsigned | NO | MUL | 2 | |
    | staff_id | int(10) unsigned | NO | MUL | 0 | |
    | email | varchar(120) | NO | | NULL | |
    | domain_name | varchar(255) | YES | | NULL | |
    | name | varchar(32) | NO | | NULL | |
    | subject | varchar(64) | NO | | [no subject] | |
    | phone | varchar(16) | YES | | NULL | |
    | ip_address | varchar(16) | NO | | NULL | |
    | status | enum('open','closed') | NO | MUL | open | |
    | source | enum('Web','Email','Phone') | YES | | NULL | |
    | isoverdue | tinyint(1) unsigned | NO | | 0 | |
    | reopened | datetime | YES | | NULL | |
    | closed | datetime | YES | | NULL | |
    | created | datetime | NO | | 0000-00-00 00:00:00 | |
    | updated | datetime | NO | | 0000-00-00 00:00:00 | |
    +-------------+-----------------------------+------+-----+---------------------+----------------+
    18 rows in set (0.00 sec)

    When creating the ticket, you can see the option to enter the info but I have two problems...I don't know how to make it a required field AND once the ticket is created, when viewing the ticket, there is no field in the ticket itself specifying "Domain Name or Company:"

    What could I be missing?
  • Could anyone assist me with this one?
  • unix4linux;5150 said:
    Could anyone assist me with this one?
    Sorry for the long wait. I try to check these forums as often as I can.

    Let me review the problem and I'll post something back.

    EDIT:

    To Make the field required changed the code you added in this file include\class.ticket.php to

    $fields['location'] = array('type'=>'text', 'required'=>1, 'error'=>'Provide a location, address, or directions'); //mod080722_new_ticket_field


    'required'=>1 being the important part. 1 = required, 0=optional

    EDIT:

    To view your new field from the ticket itself you need to edit code here:

    include\client\viewticket.inc.php for the Client Side
    include\staff\viewticket.inc.php for the Staff Side

    [HTML]

    NEW FIElD:
    <?=Format::htmlchars($ticket->getNEWFIELD())?>
    [/HTML]
  • blorenzo;4868 said:
    I have discovered that if i enter in "name" where i have the serial var, it will pull the names into the colum but not the serial. And when i enter serial into another colum it will not pull it. This leaves me to beleive its a problem with the database. But how come on all other screens (newticket,viewticket,open) it pulls the serial number and displays it. but not on tickets.php? what am i missing??
    I have PM'd this user and asked for copies of his/her files. I will post findings.
Sign In or Register to comment.