Mass Update Ticket with Regex-Search on Console

Infos:

  • Used Zammad version: 3.3.x
  • Used Zammad installation source: (source, package, …) deb
  • Operating system: ubuntu 18.04.4
  • Browser + version: chrome latest

I’ve got a tricky task from our operations-team:
They want the system to set a Tag, if an email contains a special word in subject or body. I’ve did that by using regex and that works as expected.

Now, they also want to set the tags on already existing tickets.
Does someone has a “one-liner” to crawl through all tickets, search for a regex-pattern and if found, set the tag?

This is what I came up with in our test instance:

Ticket.joins(:articles).where("ticket_articles.body ~ 'myregex'").each { |t| t.tag_add('mytag', 1) }

It’s probably a good idea to test your regex beforehand:

pp Ticket.joins(:articles).where("ticket_articles.body ~ 'myregex'"); nil

This is assuming that you’re using PostgreSQL; no idea how to match via regex in MySQL.

Replace myregex with your regex in PostgreSQL regex syntax, and mytag with the tag you want to add (1 is the ID of the user who assigns the tag, the system user seemed to be a good choice here. You can use your own user ID instead, if you want). Zammad will automatically create the tag if it doesn’t exist yet.

1 Like

works like a charm. thanks a lot!

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