Create a new ticket state with a related pending date

martini helped us out with this little howto on github:

martini commented on 14 Mar

In the meantime a small howto/workaround to add a new state via rails console (our goal is to cover it via the UI):

Add a new state, let’s say “customer feedback”:

rails c
Ticket::State.create_or_update(
  name: 'customer feedback',
  state_type_id: Ticket::StateType.find_by(name: 'open').id,
  ignore_escalation: true,
  created_by_id: 1,
  updated_by_id: 1,
)

As second you need to tell the ticket state attribute to allow it to select, here is a example, please take care (in case you are not know what you are going to do, create an database backup first)!

ObjectManager::Attribute.add(
  force: true,
  object: 'Ticket',
  name: 'state_id',
  display: 'State',
  data_type: 'select',
  data_option: {
    relation: 'TicketState',
    nulloption: true,
    multiple: false,
    null: false,
    default: Ticket::State.find_by(default_follow_up: true).id,
    translate: true,
    filter: Ticket::State.by_category(:viewable).pluck(:id),
  },
  editable: false,
  active: true,
  screens: {
    create_middle: {
      'ticket.agent' => {
        null: false,
        item_class: 'column',
        filter: Ticket::State.by_category(:viewable_agent_new).pluck(:id),
      },
      'ticket.customer' => {
        item_class: 'column',
        nulloption: false,
        null: true,
        filter: Ticket::State.by_category(:viewable_customer_new).pluck(:id),
        default: Ticket::State.find_by(default_create: true).id,
      },
    },
    edit: {
      'ticket.agent' => {
        nulloption: false,
        null: false,
        filter: Ticket::State.by_category(:viewable_agent_edit).pluck(:id),
      },
      'ticket.customer' => {
        nulloption: false,
        null: true,
        filter: Ticket::State.by_category(:viewable_customer_edit).pluck(:id),
        default: Ticket::State.find_by(default_follow_up: true).id,
      },
    },
  },
  to_create: false,
  to_migrate: false,
  to_delete: false,
  position: 40,
)

What we’re trying to do is to add a state which behaves like “pending reminder”.
The above won’t show a “pending until” field with a date selection.

Does anyone know what we have to change in the command to achieve this?

HowTo from:

Also a little HowTo from the online doc:
https://docs.zammad.org/en/latest/admin-console.html?highlight=rails#add-new-ticket-state

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.