Sample code for creating ticket

English! place to talk about development, programming and coding
Post Reply
vkandersv
Znuny newbie
Posts: 36
Joined: 07 Mar 2011, 18:32
Znuny Version: 3.0.6

Sample code for creating ticket

Post by vkandersv »

Hi,

Is there any nice/good/sweet sample code how to create a ticket the "right" way from a module - and perhaps doing some other stuff on the newly created ticket, such as adding link to another ticket, adding notes.

Sorry for asking such a basic question, but im just starting writing custom modules, and find that its not so easy to grasp the whole concept just from the manual :-)

Anders
--
ORTS 3.0.6, Linux, MySQL, ActiveDirectory integration for Customer.
jojo
Znuny guru
Posts: 15020
Joined: 26 Jan 2007, 14:50
Znuny Version: Git Master
Contact:

Re: Sample code for creating ticket

Post by jojo »

for creation of tickets via external tools please use the webservices. (Documentation on the Generic Interface and sample code can be found in the admin docs). Please have also a look on http://blog.otrs.org/2012/10/03/easy-ti ... interface/
"Production": OTRS™ 8, OTRS™ 7, STORM powered by OTRS
"Testing": ((OTRS Community Edition)) and git Master

Never change Defaults.pm! :: Blog
Professional Services:: http://www.otrs.com :: enjoy@otrs.com
vkandersv
Znuny newbie
Posts: 36
Joined: 07 Mar 2011, 18:32
Znuny Version: 3.0.6

Re: Sample code for creating ticket

Post by vkandersv »

im writing an ticket event module - so its not an external script. should i use the generic interface even though? i already have access to the ticketdata i need
--
ORTS 3.0.6, Linux, MySQL, ActiveDirectory integration for Customer.
jojo
Znuny guru
Posts: 15020
Joined: 26 Jan 2007, 14:50
Znuny Version: Git Master
Contact:

Re: Sample code for creating ticket

Post by jojo »

you wan't to create a ticket on a ticket event ?
"Production": OTRS™ 8, OTRS™ 7, STORM powered by OTRS
"Testing": ((OTRS Community Edition)) and git Master

Never change Defaults.pm! :: Blog
Professional Services:: http://www.otrs.com :: enjoy@otrs.com
vkandersv
Znuny newbie
Posts: 36
Joined: 07 Mar 2011, 18:32
Znuny Version: 3.0.6

Re: Sample code for creating ticket

Post by vkandersv »

yes, not all events, but on a few specific events, for example, (just an example) when ticketstate changes from "open" to "placed", and the queue is "orders", then i want to have a couple of child tickets automatically created, for example one ticket in another queue named "cmdb registry", and a second in a queue named "human resources". this is just an example. but what i want to achieve is a simple workflow in our ticket system - without the need for one of our agents to create those workflow tickets automatically.

i know this could go badly wrong if im not careful.
--
ORTS 3.0.6, Linux, MySQL, ActiveDirectory integration for Customer.
jojo
Znuny guru
Posts: 15020
Joined: 26 Jan 2007, 14:50
Znuny Version: Git Master
Contact:

Re: Sample code for creating ticket

Post by jojo »

webservice should also work for this...
"Production": OTRS™ 8, OTRS™ 7, STORM powered by OTRS
"Testing": ((OTRS Community Edition)) and git Master

Never change Defaults.pm! :: Blog
Professional Services:: http://www.otrs.com :: enjoy@otrs.com
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Sample code for creating ticket

Post by crythias »

You need to create a ticket, then create an article attached to the ticket.

http://dev.otrs.org

Code: Select all

TicketCreate()
creates a new ticket
    my $TicketID = $TicketObject->TicketCreate(
        Title        => 'Some Ticket Title',
        Queue        => 'Raw',            # or QueueID => 123,
        Lock         => 'unlock',
        Priority     => '3 normal',       # or PriorityID => 2,
        State        => 'new',            # or StateID => 5,
        CustomerID   => '123465',
        CustomerUser => 'customer@example.com',
        OwnerID      => 123,
        UserID       => 123,
    );
or

Code: Select all

    my $TicketID = $TicketObject->TicketCreate(
        TN            => $TicketObject->TicketCreateNumber(), # optional
        Title         => 'Some Ticket Title',
        Queue         => 'Raw',              # or QueueID => 123,
        Lock          => 'unlock',
        Priority      => '3 normal',         # or PriorityID => 2,
        State         => 'new',              # or StateID => 5,
        Type          => 'Incident',         # or TypeID => 1, not required
        Service       => 'Service A',        # or ServiceID => 1, not required
        SLA           => 'SLA A',            # or SLAID => 1, not required
        CustomerID    => '123465',
        CustomerUser  => 'customer@example.com',
        OwnerID       => 123,
        ResponsibleID => 123,                # not required
        ArchiveFlag   => 'y',                # (y|n) not required
        UserID        => 123,
    );
http://dev.otrs.org/3.1/Kernel/System/T ... ticle.html
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
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
vkandersv
Znuny newbie
Posts: 36
Joined: 07 Mar 2011, 18:32
Znuny Version: 3.0.6

Re: Sample code for creating ticket

Post by vkandersv »

Tnx,
ive started to investigate this, it seems like its possible to achieve what i want to do - and learn Perl at the same time :)
crythias wrote:You need to create a ticket, then create an article attached to the ticket.

http://dev.otrs.org

Code: Select all

TicketCreate()
creates a new ticket
    my $TicketID = $TicketObject->TicketCreate(
        Title        => 'Some Ticket Title',
        Queue        => 'Raw',            # or QueueID => 123,
        Lock         => 'unlock',
        Priority     => '3 normal',       # or PriorityID => 2,
        State        => 'new',            # or StateID => 5,
        CustomerID   => '123465',
        CustomerUser => 'customer@example.com',
        OwnerID      => 123,
        UserID       => 123,
    );
or

Code: Select all

    my $TicketID = $TicketObject->TicketCreate(
        TN            => $TicketObject->TicketCreateNumber(), # optional
        Title         => 'Some Ticket Title',
        Queue         => 'Raw',              # or QueueID => 123,
        Lock          => 'unlock',
        Priority      => '3 normal',         # or PriorityID => 2,
        State         => 'new',              # or StateID => 5,
        Type          => 'Incident',         # or TypeID => 1, not required
        Service       => 'Service A',        # or ServiceID => 1, not required
        SLA           => 'SLA A',            # or SLAID => 1, not required
        CustomerID    => '123465',
        CustomerUser  => 'customer@example.com',
        OwnerID       => 123,
        ResponsibleID => 123,                # not required
        ArchiveFlag   => 'y',                # (y|n) not required
        UserID        => 123,
    );
http://dev.otrs.org/3.1/Kernel/System/T ... ticle.html
--
ORTS 3.0.6, Linux, MySQL, ActiveDirectory integration for Customer.
Post Reply