A tutorial on Ticket Events

Dont create your support topics here! No new topics with questions allowed!

Moderator: crythias

Post Reply
User avatar
crythias
Moderator
Posts: 9980
Joined: 04 May 2010, 18:38
OTRS Version?: 5.0.x
Location: SouthWest Florida, USA
Contact:

A tutorial on Ticket Events

Post by crythias » 11 Jun 2011, 03:32

https://github.com/OTRS/TemplateModule

What's a Ticket Event?
When a ticket does an action, this can do something based upon that action method.

What kind of action methods can I use/run against?
https://github.com/OTRS/TemplateModule/ ... mplate.xml

ArticleAgentNotification
ArticleAutoResponse
ArticleBounce
ArticleCreate
ArticleCustomerNotification
ArticleFlagDelete
ArticleFlagSet
ArticleFreeTextUpdate
ArticleSend
ArticleUpdate
HistoryAdd
HistoryDelete
TicketAccountTime
TicketCreate
TicketCustomerUpdate
TicketDelete
TicketFreeTextUpdate
TicketFreeTimeUpdate
TicketLockUpdate
TicketMerge
TicketOwnerUpdate
TicketPendingTimeUpdate
TicketPriorityUpdate
TicketQueueUpdate
TicketResponsibleUpdate
TicketServiceUpdate
TicketSLAUpdate
TicketStateUpdate
TicketTitleUpdate
TicketTypeUpdate
TicketUnlockTimeoutUpdate

What do I need?
  • An idea.
  • An editor.
  • A grasp of the perl language.
  • A link to the API
The components of a Ticket Event are:
  1. An XML file in Kernel/Config/Files pointing to the TicketEvent
  2. A TicketEventYourInfoHere.pm in Kernel/System/Ticket/Event/
The XML file:

Code: Select all

<?xml version="1.0" encoding="utf-8" ?>
<otrs_config version="1.0" init="Changes">
    <ConfigItem Name="Ticket::EventModulePost###EventModulePostTemplate" Required="0" Valid="1">
        <Description Lang="en"></Description>
        <Description Lang="de"></Description>
        <Group>EventModulePostTemplate</Group>
        <SubGroup>EventModule</SubGroup>
        <Setting>
            <Hash>
                <Item Key="Module">Kernel::System::Ticket::Event::EventModulePostTemplate</Item>
                <Item Key="Event">(ArticleAgentNotification|ArticleAutoResponse|ArticleBounce|ArticleCreate|ArticleCustomerNotification|ArticleFlagDelete|ArticleFlagSet|ArticleFreeTextUpdate|ArticleSend|ArticleUpdate|HistoryAdd|HistoryDelete|TicketAccountTime|TicketCreate|TicketCustomerUpdate|TicketDelete|TicketFreeTextUpdate|TicketFreeTimeUpdate|TicketLockUpdate|TicketMerge|TicketOwnerUpdate|TicketPendingTimeUpdate|TicketPriorityUpdate|TicketQueueUpdate|TicketResponsibleUpdate|TicketServiceUpdate|TicketSLAUpdate|TicketStateUpdate|TicketTitleUpdate|TicketTypeUpdate|TicketUnlockTimeoutUpdate)</Item>
            </Hash>
        </Setting>
    </ConfigItem>
</otrs_config>
The most critical parts of this entry:
  1. <ConfigItem Name="Ticket::EventModulePost###EventModulePostTemplate" Required="0" Valid="1"> (Ticket::EventModulePost is always this. Grouping maybe something else, but Ticket::EventModulePost is required. After ###, anything you want to say.)
  2. <Item Key="Module">Kernel::System::Ticket::Event::EventModulePostTemplate</Item> Path is important, but name (EventModulePostTemplate) isn't. Just make sure the file it references exists in the path, and has a Package name (inside the file)that is the same thing. The Package name should be the same as the path without the .pm
  3. <Item Key="Event"> Every event is listed here. You don't need all of them, just the ones that you want to call your event. Use parentheses when referencing more than one: (TicketLockUpdate|TicketMerge)
The .pm file:
https://github.com/OTRS/TemplateModule/ ... emplate.pm
Most critical:

Code: Select all

package Kernel::System::Ticket::Event::EventModulePostTemplate;
(this should reflect the path of the file. If you change the filename, change the last of the package line.)

Built-in Objects that can be used:
ConfigObject CustomerGroupObject CustomerUserObject DBObject EncodeObject GroupObject
HTMLUtilsObject LinkObject LockObject LogObject LoopProtectionObject MainObject
PriorityObject QueueObject SendmailObject ServiceObject SLAObject StateObject
TicketObject TimeObject TypeObject UserObject ValidObject

You need a sub new { } and a sub Run{ }
the sub new { ... } is standard fare. Just copy it and paste it.

the sub Run { ... } is where the action is. Remember that all of the above list also creates Events. Avoid making an infinite loop event, such as an event that reacts to HistoryAdd and then uses the API which triggers a HistoryAdd event.
Last edited by crythias on 18 Aug 2014, 15:29, edited 2 times in total.
OTRS 5.0.x (private/testing/public) on Linux with MySQL database. Also on github.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask

User avatar
crythias
Moderator
Posts: 9980
Joined: 04 May 2010, 18:38
OTRS Version?: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: A tutorial on Ticket Events

Post by crythias » 14 Sep 2011, 16:16

For specific questions on an implementation, please open a topic in the help forums. The HowTo forum is moderated for the purpose of providing information, not for answering questions.
OTRS 5.0.x (private/testing/public) on Linux with MySQL database. Also on github.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask

tnieman
OTRS wizard
Posts: 103
Joined: 14 Nov 2012, 21:59
OTRS Version?: 3.1.6
Real Name: Tom Nieman
Company: WorkForce Software

Re: A tutorial on Ticket Events

Post by tnieman » 14 Aug 2014, 20:10

This link is not working - getting a page not found error

http://source.otrs.org/viewvc.cgi/Templ ... iew=markup


Tom

User avatar
crythias
Moderator
Posts: 9980
Joined: 04 May 2010, 18:38
OTRS Version?: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: A tutorial on Ticket Events

Post by crythias » 18 Aug 2014, 15:29

updated.
OTRS 5.0.x (private/testing/public) on Linux with MySQL database. Also on github.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask

tnieman
OTRS wizard
Posts: 103
Joined: 14 Nov 2012, 21:59
OTRS Version?: 3.1.6
Real Name: Tom Nieman
Company: WorkForce Software

Re: A tutorial on Ticket Events

Post by tnieman » 18 Aug 2014, 18:45

Thanks!

Post Reply