Once upon a time there was no way to add searching capabilities to custom user fields in osTicket. I found a forum post detailing how to do it when searching the user list. But there was nothing on how to get it done when creating a ticket.
That is until I figured out how to get it done…
In order to do this, you must edit the source code directly. When you update your installation, you will need to (1) pray that they haven’t so modified the new code that you can’t re-apply this fix and (2) then go and figure out how to re-apply this fix.
I did this with osTicket 1.15 in March of 2021 and it works pretty well. If you’re running an older version of osTicket, the process is likely the same although the code may not be in the same place.
You will need the variable name of your custom field, which you can obtain from the admin panel. If you are unsure of how to work with forms or custom fields, please review the osTicket documentation Forms page for details on this process.
In order to display the custom field in a user modal when creating a ticket, you will need to customize the Contact Information form. The variable name that is used in the examples below can be found there:
To search a custom field in the quick search under the users tab you will need to find the
file and find the code that looks like this for the phone field:include/staff/users.inc.php
if (UserForm::getInstance()->getField('phone')) $filter->add(array('cdata__phone__contains' => $search));
Then you can copy and paste that code and change the ‘phone’ variable to the variable name of your custom field right below the previous code. You can repeat this for as many custom fields as you may have.
if (UserForm::getInstance()->getField('variableName')) $filter->add(array('cdata__variableName__contains' => $search));
So this was what the forum post I mentioned said to do, which was great. But it wasn’t enough. When I went to create new tickets, I couldn’t search for my custom field. So I had to do a little digging and found that the modal dialog uses a file located at
. In that file on line 83 I found the following code:include/ajax.users.php
if (UserForm::getInstance()->getField('phone')) { UserForm::ensureDynamicDataView(); $filter->add(array('cdata__phone__contains' => $q)); }
Following the previous example, I copied that code and modified it to include my custom field’s variable name, like this:
if (UserForm::getInstance()->getField('variableName')) { UserForm::ensureDynamicDataView(); $filter->add(array('cdata__variableName__contains' => $q)); }
Now when the popup modal appears on the ticket creation screen, I can type my custom variable and it will locate the desired user just as the user search does above.