New phone ticket:Createticket Event setowner not working

English! place to talk about development, programming and coding
Post Reply
marcmoennikes
Znuny newbie
Posts: 17
Joined: 30 Apr 2012, 15:47
Znuny Version: 3.1.4
Real Name: Marc Moennikes
Company: KKRN

New phone ticket:Createticket Event setowner not working

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>
Post Reply