issue with postmaster filter

English! place to talk about development, programming and coding
Post Reply
jj99
Znuny newbie
Posts: 36
Joined: 11 Apr 2013, 16:31
Znuny Version: 2.3.4
Company: Student

issue with postmaster filter

Post by jj99 »

Hi I develop a postmaster filter for linking a new ticket with changes if a email with change number arrives in a otrs system then the system should create a new ticket and link it with existing change.

But i am getting this error: Got no UserObject! at /opt/otrs/Kernel/System/ITSMChange.pm line 108.

Code: Select all

# --
# Kernel/System/PostMaster/Filter/Test.pm - sub part of PostMaster.pm
# --
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --
 
package Kernel::System::PostMaster::Filter::Test

use strict;
use warnings;

use Kernel::System::ITSMChange;
use Kernel::System::Email;
use Kernel::System::Ticket;
use Kernel::System::LinkObject;

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

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

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

    $Self->{Debug} = $Param{Debug} || 0;

    # get needed objects
    for (qw
	(DBObject ConfigObject LogObject MainObject)
		) {
        $Self->{$_} = $Param{$_} || die "Got no $_!";
    }

    $Self->{ChangeObject} = Kernel::System::ITSMChange->new(%Param);
    $Self->{EmailObject}  = Kernel::System::Email->new(%Param);
    $Self->{TicketObject} = Kernel::System::Ticket->new(%Param);
    $Self->{LinkObject} = Kernel::System::LinkObject->new(%Param);

    return $Self;
}

sub Run {
    my ( $Self, %Param ) = @_;
	
	
     my $CrNumber;
	 
    # check needed stuff
    for (qw(JobConfig GetParam)) {
        if ( !$Param{$_} ) {
            $Self->{LogObject}->Log( Priority => 'error', Message => "Need $_!" );
            return;
        }
    }

    # Search for Changes with the Change Number
    my %MailParams = %{ $Param{GetParam} || {} };
    
    #Check for desired email address
    if ( $Param{GetParam}->{From} =~m/otrstest/i ) {
        $Self->{LogObject}->Log( Priority => 'debug', Message  => "Change Request Mail: match sender $Param{GetParam}->{From}" );
    } else {
        $Self->{LogObject}->Log( Priority => 'debug', Message  => "Change Request Mail: no match (Sender $Param{GetParam}->{From})" );
        return 1;
    }
    #Extract the change Number from Mail Subject
    my @SubjectLines = split /\n/, $Param{GetParam}->{Subject};
 
    for my $Line (@SubjectLines) {
    	# Get the first number in subject (e.g. Change Request#: 123456 - Something), It will store only 123456
    	
    	( $CrNumber  = $Line =~ /([0-9]+) .*/ ); 
    }
    #Search for change with CrNumber as input
    my $ChangeID = $Self->{ChangeObject}->ChangeSearch(
		UserID       => 1,
        ChangeNumber => $CrNumber,
        
    );
	

    # Create a new ticket and link ticket with existing change if change number found in mail subject
    if ( $ChangeID ) {
       my $TicketID = $Self->{TicketObject}->TicketCreate(
	  
        Title        => 'Some Ticket Title',
        Queue        => 'otrs',           
        Priority     => '3 normal',       
        State        => 'new', 
	Type          => 'RfC', 		
        UserID		=> 1,   
	OwnerID      => 1,
       
    );
	my $Link = $Self->{LinkObject}->LinkAdd(
        SourceObject => 'ITSMChange',
        SourceKey    =>  $ChangeID,
        TargetObject => 'Ticket',
        TargetKey    => $TicketID,
        Type         => 'Normal',
        State        => 'Valid',
        UserID       => 1,
    );
    }
  # logging
    $Self->{LogObject}->Log(
        Priority => 'notice',
        Message  => "Change Request Mail: $Param{GetParam}->{Subject}",
    );
    return 1;
}

1;
nagabhus
Znuny newbie
Posts: 5
Joined: 20 Dec 2013, 09:00
Znuny Version: otrs-3.2.2

Re: issue with postmaster filter

Post by nagabhus »

Hi,

I'm facing the same issue with my script. Was this resolved? If so, could you please share your thoughts?

Many Thanks
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: issue with postmaster filter

Post by reneeb »

The error message says it all ;-)

Code: Select all

package Kernel::System::PostMaster::Filter::Test

[...]
use Kernel::System::ITSMChange;
use Kernel::System::User;
[...]

sub new {
[...]

    $Self->{UserObject}    = Kernel::System::User->new(%Param);
    $Self->{ChangeObject} = Kernel::System::ITSMChange->new(%Param, %{$Self});
[...]
    return $Self;
}

[...]
(I removed some code for readabilitys sake)
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
Post Reply