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

set value of custom form field on ticket create (plugin)

osTicket Version v1.10 (901e5ea) —  Up to date
Web Server Software Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips PHP/5.6.31
MySQL Version 5.5.52
PHP Version 5.6.31

I am trying to create a plugin which submits new ticket details to another API and get an Id in return. I have a custom field in the ticket details form where I would like to store this Id.
So far I got everything working except I am unable to set the value of the custom field. It seems that I have to do this somehow via forms and DynamicFormField but I couldn't find an example and getting nowhere with just trial and error.

I am using the Signal "ticket.created".

thanks in advance


  • I wouldn't create a plugin to do this.  I would setup a standalone script (think email form that uses the API to open a ticket) that grabed the value from the other DB and included it in the ticket open.
  • thanks for the fast response. The section did help indeed and I have it kind of working now.
    It seems that by setting it via form I have to also set all the other custom fields (subject, priority, message) or otherwise they will be empty.

    So this is how I did it in case someone wants to know:

    $form = TicketForm::getNewInstance();
    $form->setAnswer('subject', $ticket->getSubject());
    $form->setAnswer('priority', $ticket->getPriorityId());
    $form->setAnswer('customid', $custom_id);

    Not sure on what to put into the message field though as nothing seems to be missing. $ticket->getLastMessage()?

    Also I am not sure if this will not just create another entry in the database instead of changing the one that already exists

    I thought of this but since there was already a plugin available which almost did the same thing I thought this would be the easiest way.
  • My posted solution does create a new entry in the database. So after some more trial and error I was able to get the already created entry and update only the custom field.

    $forms = DynamicFormEntry::forTicket($ticket->getId());
    if (count($forms) == 1) {
    $form = $forms->first();
    $form->setAnswer('customid', $custom_id);
  • Cheers for that update mate.
Sign In or Register to comment.