Event CreateTicket "Change owner" to Agent root

Moderator: crythias

Locked
marcmoennikes
Znuny newbie
Posts: 17
Joined: 30 Apr 2012, 15:47
Znuny Version: 3.1.4
Real Name: Marc Moennikes
Company: KKRN

Event CreateTicket "Change owner" to Agent root

Post by marcmoennikes »

Hello,

i am trying to achieve the following:
When a new ticket is created (telephone ticket) the owner should be set to "root@localhost"
I have tried to use a ticket event, on ticket create.

You will find the xml and pm code at the end of the post.

I have copied some code from the "ForceOwnerReset.pm".
i have added the "write something to history part". so i can see, the event is fired.
When i create a new ticket, the history part is added, so i think the event is active.
But the owner is not changed.
Maybe somebody can help me?

Thank you

Regards

The pm file

Code: Select all

package Kernel::System::Ticket::Event::SetOwnerRoot;

use strict;
use warnings;

# use vars qw($VERSION);
# $VERSION = qw($Revision: 1.3 $) [1];

sub new {
    my ( $Type, %Param ) = @_;

    # allocate new hash for object
    my $Self = {};
    bless( $Self, $Type );

    # get needed objects
    for (
        qw(ConfigObject TicketObject PriorityObject SLAObject LogObject UserObject CustomerUserObject SendmailObject TimeObject EncodeObject)
        )
    {
        $Self->{$_} = $Param{$_} || die "Got no $_!";
    }

    return $Self;
}

sub Run {
    my ( $Self, %Param ) = @_;

    # check needed stuff
    for (qw(Data Event Config)) {
        if ( !$Param{$_} ) {
            $Self->{LogObject}->Log( Priority => 'error', Message => "Need $_!" );
            return;
        }
    }
    for (qw(TicketID)) {
        if ( !$Param{Data}->{$_} ) {
            $Self->{LogObject}->Log( Priority => 'error', Message => "Need $_ in Data!" );
            return;
        }
    }

    # get ticket
    my %Ticket = $Self->{TicketObject}->TicketGet(
        TicketID      => $Param{Data}->{TicketID},
       # UserID        => 1,
    );
 #   return if !%Ticket;
   
  # reset owner
    $Self->{TicketObject}->TicketOwnerSet(
        TicketID           => $Param{Data}->{TicketID},
        NewUserID          => 1,
        SendNoNotification => 1,
        UserID             => $Param{UserID},
    );
	# History add
	$Self->{TicketObject}->HistoryAdd(
                TicketID     => $Param{Data}->{TicketID},
                CreateUserID => $Param{UserID},
                HistoryType  => 'Misc',
                Name         => 'Some Info about Changes!',
            );


    # unlock ticket
    $Self->{TicketObject}->TicketLockSet(
        TicketID           => $Param{Data}->{TicketID},
        Lock               => 'unlock',
        SendNoNotification => 1,
        UserID             => 1,
    );
    return 1;
the xml file (i think there is no error):

Code: Select all

<?xml version="1.0" encoding="utf-8" ?>
<otrs_config version="1.0" init="Changes">
    <ConfigItem Name="Ticket::EventModulePost###SetOwnerRoot" Required="0" Valid="1">
        <Description Lang="en">Set Owner to root at ticket creation</Description>
        <Group>SetOwnerRoot</Group>
        <SubGroup>EventModule</SubGroup>
        <Setting>
            <Hash>
                <Item Key="Module">Kernel::System::Ticket::Event::SetOwnerRoot</Item>
                <Item Key="Event">TicketCreate</Item>
            </Hash>
        </Setting>
    </ConfigItem>
</otrs_config>
marcmoennikes
Znuny newbie
Posts: 17
Joined: 30 Apr 2012, 15:47
Znuny Version: 3.1.4
Real Name: Marc Moennikes
Company: KKRN

Re: Event CreateTicket "Change owner" to Agent root

Post by marcmoennikes »

Sorry, maybe wrong forum. I have posted the question now in the developer forum.

Regards
marcmoennikes
Znuny newbie
Posts: 17
Joined: 30 Apr 2012, 15:47
Znuny Version: 3.1.4
Real Name: Marc Moennikes
Company: KKRN

Re: Event CreateTicket "Change owner" to Agent root

Post by marcmoennikes »

Hello,

myabe there is no way to do this with an event.

Does somebody knows a way to configure the following:
For every new phone ticket where owner is "-" (no owner specified) set the owner to a specified agent, like root@localhost?

Regards
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Event CreateTicket "Change owner" to Agent root

Post by reneeb »

I have done this for one of my customers. It's a bit tricky as a new owner is set anyway (if "-" is selected, the owner is set to the agent who created the ticket) after the ticket creation (and after the TicketCreate event). So you have to listen to the TicketOwnerUpdate event and check if it is the first owner update after ticket creation...
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
marcmoennikes
Znuny newbie
Posts: 17
Joined: 30 Apr 2012, 15:47
Znuny Version: 3.1.4
Real Name: Marc Moennikes
Company: KKRN

Re: Event CreateTicket "Change owner" to Agent root

Post by marcmoennikes »

Hello,

thanks for your reply.
Grat hint about the "ticketownerupdate".
I understand, the ticketcreate event is not the right way, because it is overwritten.
Maybe you can give me some deeper information about checking for first owner update?

Regards
wurzel
Znuny guru
Posts: 3274
Joined: 08 Jul 2010, 22:25
Znuny Version: x.x.x
Real Name: Florian

Re: Event CreateTicket "Change owner" to Agent root

Post by wurzel »

Hi,

Why change code? Does your Event Based Action on the 3.3.x not work? ;)

I would ask, does it make sense to set the owner to root@localhost?

Flo
OTRS 2025 SILVER (Prod)
OTRS 2025 auf Debian 12 (Test)
Znuny 7.x latest version testing auf Debian 12

-- Ich beantworte keine Forums-Fragen PN - No PN please

I won't answer to unfriendly users any more. A greeting and regards are just polite.
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Event CreateTicket "Change owner" to Agent root

Post by reneeb »

@wurzel: The ticket event should work in OTRS 3.3 as before... I've seen companies where a ticket owner "root@localhost" means "grab the ticket if you search for work ;-)". My customer doesn't set the owner to root@localhost but to a dispatch person...

@marcmoennikes: You have to check if this is a event triggered by a web form (loop through the "caller()" and check if the calling package is Kernel::Modules::Agent...). If it is a "webrequest", go through the history and count the number of TicketOwnerUpdate events.
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
Locked