(SOLVED) Update SLA upon Ticket Event

Moderator: crythias

Locked
Kullab
Znuny newbie
Posts: 3
Joined: 06 Nov 2012, 20:25
Znuny Version: 3.1.11
Real Name: FHR
Company: H3C

(SOLVED) Update SLA upon Ticket Event

Post by Kullab »

Hello,
I'm trying to make my own Ticket Event action, based on crythias' very helpful tutorial http://forums.otrs.org/viewtopic.php?f=60&t=10090.
What I'm trying to do is quite simple (I think...) : I just want the Ticket SLA to be automatically updated as soon as the Ticket Priority has been set for the first time or changed (in other words : link SLA to priority).
In my current code, which is only a test, I'm trying to set the Ticket SLA to the value "Platinium" as soon as the Ticket Priority is modified.

Here is the xml file code (name: PrioritySLAUpdate.xml, placed in Kernel\Config\Files directory):

Code: Select all

<?xml version="1.0" encoding="utf-8" ?>
<otrs_config version="1.0" init="Changes">
    <ConfigItem Name="Ticket::EventModulePost###PrioritySLAUpdate" Required="0" Valid="1">
        <Description Lang="en">Update SLA based on ticket Priority</Description>
        <Group>PrioritySLAUpdate</Group>
        <SubGroup>EventModule</SubGroup>
        <Setting>
            <Hash>
                <Item Key="Module">Kernel::System::Ticket::Event::PrioritySLAUpdate</Item>
                <Item Key="Event">TicketPriorityUpdate</Item>
            </Hash>
        </Setting>
    </ConfigItem>
</otrs_config>
And here is the pm file code (name: PrioritySLAUpdate.pm, placed in Kernel\System\Ticket\Event directory):

Code: Select all

# --
# Kernel/System/Ticket/Event/PrioritySLAUpdate.pm - unlock ticket
# Copyright (C) 2001-2010 xxx, http://otrs.org/
# --
# $Id: PrioritySLAUpdate.pm,v 1.0 2010/05/19 07:08:18 mb Exp $
# --
# 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::Ticket::Event::PrioritySLAUpdate;

use strict;
use warnings;

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

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

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

    # get needed objects
    for (
        qw(
        ConfigObject CustomerGroupObject CustomerUserObject DBObject EncodeObject GroupObject
        HTMLUtilsObject LinkObject LockObject LogObject LoopProtectionObject MainObject
        PriorityObject QueueObject SendmailObject ServiceObject SLAObject StateObject
        TicketObject TimeObject TypeObject UserObject ValidObject
        )
        )
    {
        $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;
        }
    }

    # update SLA
    $Self->{TicketObject}->TicketSLASet(
        TicketID    => $Param{Data}->{TicketID},
        UserID      => $Param{UserID},
        SLA  		=> 'Platinium',  
    );
	
    return 1;
}

1;
Unfortunately, after a great number of hours of work, it still doesn't work : nothing happens.
Could you please help me ?
Last edited by Kullab on 11 Dec 2012, 20:30, edited 1 time in total.
OTRS 3.3 on Linux with Apache and MySQL database
ITSM and FAQ
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Update SLA upon Ticket Event

Post by crythias »

did you check the section is enabled within sysconfig?
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
Kullab
Znuny newbie
Posts: 3
Joined: 06 Nov 2012, 20:25
Znuny Version: 3.1.11
Real Name: FHR
Company: H3C

Re: Update SLA upon Ticket Event

Post by Kullab »

Thank you crythias, I wasn't aware of this parameter in sysconfig, it helped a lot.
I finally managed to make this work, so I will post the .pm and .xml files below in case anyone is interested.

The .xml file :

Code: Select all

<?xml version="1.0" encoding="utf-8" ?>
<otrs_config version="1.0" init="Changes">
    <ConfigItem Name="Ticket::EventModulePost###PrioritySLAUpdate" Required="0" Valid="1">
        <Description Lang="en">Update SLA based on ticket Priority</Description>
        <Group>PrioritySLAUpdate</Group>
        <SubGroup>EventModule</SubGroup>
        <Setting>
            <Hash>
                <Item Key="Module">Kernel::System::Ticket::Event::PrioritySLAUpdate</Item>
                <Item Key="Event">TicketCreate|TicketPriorityUpdate</Item>
            </Hash>
        </Setting>
    </ConfigItem>
</otrs_config>
The .pm file :

Code: Select all

# --
# Kernel/System/Ticket/Event/PrioritySLAUpdate.pm - Empty pending time on status change
# Copyright (C) 2001-2011 xxx, http://otrs.org/
# --
# $Id: PrioritySLAUpdate.pm,v 1.3 2011/11/25 10:14:18 mg Exp $
# --
# 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::Ticket::Event::PrioritySLAUpdate;

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;
	
	# chaine if	
	
    if ( $Ticket{PriorityID} eq 5 ) {
        # update with SLA 1
		$Self->{TicketObject}->TicketSLASet(
			SLAID  		 => 1, 
			TicketID     => $Param{Data}->{TicketID},
			UserID       => $Param{UserID},         
		);	
    }	
	
    elsif ( $Ticket{PriorityID} eq 4 ) {
        # update with SLA 2
		$Self->{TicketObject}->TicketSLASet(
			SLAID  		 => 2, 
			TicketID     => $Param{Data}->{TicketID},
			UserID       => $Param{UserID},         
		);	
    }	
	
    elsif ( $Ticket{PriorityID} eq 3 ) {
        # update with SLA 3
		$Self->{TicketObject}->TicketSLASet(
			SLAID  		 => 3, 
			TicketID     => $Param{Data}->{TicketID},
			UserID       => $Param{UserID},         
		);	
    }	
	
    elsif ( $Ticket{PriorityID} eq 1 ) {
        # update with SLA 4
		$Self->{TicketObject}->TicketSLASet(
			SLAID  		 => 4, 
			TicketID     => $Param{Data}->{TicketID},
			UserID       => $Param{UserID},         
		);	
    }	
	
    return 1;
}

1;
crythias, thanks again for answering me so fast.
OTRS 3.3 on Linux with Apache and MySQL database
ITSM and FAQ
ptitsans
Znuny newbie
Posts: 5
Joined: 10 Mar 2014, 12:50
Znuny Version: version 3.3

Re: (SOLVED) Update SLA upon Ticket Event

Post by ptitsans »

Thank you kullab for your Code.
I have juste one question, What is the parameter in SysConfig to enable?

Thank you,

Florian
OTRS 3.3.5
MySQL
OS : CentOS 6.4
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: (SOLVED) Update SLA upon Ticket Event

Post by crythias »

Btw, this is not recommended to do. viewtopic.php?f=53&t=16009#p80263
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
ptitsans
Znuny newbie
Posts: 5
Joined: 10 Mar 2014, 12:50
Znuny Version: version 3.3

Re: (SOLVED) Update SLA upon Ticket Event

Post by ptitsans »

Thanks crythias,

I don't want to implement an Event to link SLA and Priority but modify the Event SLA Update Time (When the event start, stop and restart).
So, I just would like to test the event and undestand ticket Event to adapt my OTRS solution.

Florian
OTRS 3.3.5
MySQL
OS : CentOS 6.4
Kullab
Znuny newbie
Posts: 3
Joined: 06 Nov 2012, 20:25
Znuny Version: 3.1.11
Real Name: FHR
Company: H3C

Re: (SOLVED) Update SLA upon Ticket Event

Post by Kullab »

Hi ptitsans,

Sorry for the delay.
Go to Administration > SysConfig, and search for "event".
The EventModule you just created should appear with the name and description you gave him, in my case "PrioritySLAUpdate"
Verify that it is valid.

Hope this helps,
Regards
OTRS 3.3 on Linux with Apache and MySQL database
ITSM and FAQ
Locked