Unable to add new Ticket State with error

Infos:

  • Used Zammad version: 3.4
  • Used Zammad installation source: source
  • Operating system: Ubuntu 18.04.4
  • Browser + version: Google Chrome Version 83.0.4103.106 (Official Build) (64-bit)

I not familiar with Rails, and I try follow the documentation to add a new ticket state but comes out error.

Expected behavior:

Documentation: https://docs.zammad.org/en/latest/admin/console/working-on-tickets.html

  1. sudo zammad run rails c

  2. Ticket::State.create_or_update(
    name: ‘resolved’,
    state_type: Ticket::StateType.find_by(name: ‘resolved’),
    ignore_escalation: true,
    active:true,
    created_by_id: 1,
    updated_by_id: 1,
    )

  3. attribute = ObjectManager::Attribute.get(
    object: ‘Ticket’,
    name: ‘state_id’,
    )
    attribute.data_option[:filter] = Ticket::State.by_category(:viewable).pluck(:id)
    attribute.screens[:create_middle][‘ticket.agent’][:filter] = Ticket::State.by_category(:viewable_agent_new).pluck(:id)
    attribute.screens[:create_middle][‘ticket.customer’][:filter] = Ticket::State.by_category(:viewable_customer_new).pluck(:id)
    attribute.screens[:edit][‘ticket.agent’][:filter] = Ticket::State.by_category(:viewable_agent_edit).pluck(:id)
    attribute.screens[:edit][‘ticket.customer’][:filter] = Ticket::State.by_category(:viewable_customer_edit).pluck(:id)
    attribute.save!

  4. The ticketing UI, new States “resolved” should appear in the selection list.
    image

Actual behavior:

When run the rails command to add new state:
Ticket::State.create_or_update(
name: ‘resolved’,
state_type: Ticket::StateType.find_by(name: ‘resolved’),
ignore_escalation: true,
active:true,
created_by_id: 1,
updated_by_id: 1,
)

ERROR: NotNullViolation on “state_type_id”
image

There is no Ticket-State-Type “resolved” which is why your command is failing.
To list all ticket state types have a look at: Working with ticket information — Zammad System Documentation documentation

Sorry, I don’t understand.

This Rails command is to ADD? or to UPDATE?

My intention is to ADD a new state named “resolved”, instead of UPDATE (overwrite) existing state in the table.

The documentation states that, if you want to add or update states you may need to know the ticket state types that are available.

A state consists of the state itself and a state type which describes what kind of type it is (like e.g. “pending action”).

Those actions described on the documentation are suitable for updating existing states and adding new ones.

Oh! Now I get it.

I thought this is a kinds of SQL Statement, to insert a new record into table.

Now, I managed to add new ticket closed state, “resolved”, with the Rails command.

Thank you so much MrGeneration.

1 Like

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