How to Chnage Ticket Status when ticket is Locked

Moderator: crythias

Locked
abhijitsarangi
Znuny newbie
Posts: 12
Joined: 21 Feb 2011, 08:19
Znuny Version: otrs-2.4.7-01

How to Chnage Ticket Status when ticket is Locked

Post by abhijitsarangi »

Dear All,

I am planning to use OTRS as my ticket management system. I have configured most of the functionality as per my requirement. Only thing I am struggling now is , I want to change the status of the ticket to "Work In Progress" whenever an Agent Locks it. It should happen automatically i;e the Lock event should change the status to work in progress. I have already created one status as Work In Progress , but I don't know how to integrate with Lock event. Is it possible guys???? If yes please help me or guide me how to go about it.

All the reply will be appreciated

Thanks in advance.
renee
Znuny expert
Posts: 241
Joined: 06 Feb 2009, 11:15
Znuny Version: 3.0.x
Company: Perl-Services.de
Contact:

Re: How to Chnage Ticket Status when ticket is Locked

Post by renee »

You need a module for that event:

Code: Select all

# --
# Kernel/System/Ticket/Event/SetStateOnLock.pm - a event module
# Copyright (C) 2010-2011 perl-services.de, http://perl-services.de/
# --
# $Id: SetStateOnLock.pm,v 1.5 2011/05/31 13:28:21 rb 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::SetStateOnLock;

use strict;
use warnings;

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

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

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

    # get needed objects
    for my $Needed (
        qw(DBObject ConfigObject TicketObject LogObject QueueObject MainObject EncodeObject TimeObject)
        )
    {
        $Self->{$Needed} = $Param{$Needed} || die "Got no $Needed!";
    }

    return $Self;
}

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

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

    return 1 if $Param{Event} ne 'TicketQueueUpdate'; # we just want to act when the ticket is moved

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

    my $TicketID = $Param{TicketID};
    $Self->{TicketObject}->TicketStateSet(
        TicketID => $TicketID,
        UserID => 1,
        State => 'Work In Progress',
    );

    return 1;
}

1;
And add this in Kernel/Config.pm:

Code: Select all

$Self->{'Ticket::EventModulePost'}->{'110-SetStateOnLock'} =  {
  'Event' => '(TicketLockUpdate)', # Here you register the events you want to listen to
  'Module' => 'Kernel::System::Ticket::Event::SetStateOnLock', # the module that is called for those events
};
Need a Perl/OTRS developer? You can contact me at info@perl-services.de
abhijitsarangi
Znuny newbie
Posts: 12
Joined: 21 Feb 2011, 08:19
Znuny Version: otrs-2.4.7-01

Re: How to Chnage Ticket Status when ticket is Locked

Post by abhijitsarangi »

Dear Renee,

Thanks a lot for your quick reply. I have tried to implement the module but I am unable to see the result. The state is still new at customer end even though the ticket is locked by the agent. But according to the code customer should see the state as work in progress..
renee
Znuny expert
Posts: 241
Joined: 06 Feb 2009, 11:15
Znuny Version: 3.0.x
Company: Perl-Services.de
Contact:

Re: How to Chnage Ticket Status when ticket is Locked

Post by renee »

Copy'n'paste error:

Code: Select all

return 1 if $Param{Event} ne 'TicketQueueUpdate'; # we just want to act when the ticket is moved
has to substituted with

Code: Select all

return 1 if $Param{Event} ne 'TicketLockUpdate';
Maybe an other check has to be added, too: Check if ticket is locked or unlocked...
Need a Perl/OTRS developer? You can contact me at info@perl-services.de
abhijitsarangi
Znuny newbie
Posts: 12
Joined: 21 Feb 2011, 08:19
Znuny Version: otrs-2.4.7-01

Re: How to Chnage Ticket Status when ticket is Locked

Post by abhijitsarangi »

Really appriciate your effort, but there is no change in the state even after I made the code changes as suggested by you. It's really defficult for me to track the error as I am completely new to perl script. Please suggest how to trace the error and proceed.

I have checket thet the ticket is locked.

please find the attached to have a beetter understanding of the issue.
You do not have the required permissions to view the files attached to this post.
renee
Znuny expert
Posts: 241
Joined: 06 Feb 2009, 11:15
Znuny Version: 3.0.x
Company: Perl-Services.de
Contact:

Re: How to Chnage Ticket Status when ticket is Locked

Post by renee »

Ok, use this code:

Code: Select all

# --
# Kernel/System/Ticket/Event/SetStateOnLock.pm - a event module
# Copyright (C) 2010-2011 perl-services.de, http://perl-services.de/
# --
# $Id: SetStateOnLock.pm,v 1.5 2011/05/31 13:28:21 rb 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::SetStateOnLock;

use strict;
use warnings;

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

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

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

    # get needed objects
    for my $Needed (
        qw(DBObject ConfigObject TicketObject LogObject QueueObject MainObject EncodeObject TimeObject)
        )
    {
        $Self->{$Needed} = $Param{$Needed} || die "Got no $Needed!";
    }

    return $Self;
}

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

    $Self->{LogObject}->Log(
        Priority => 'error',
        Message => 'Run SetStateOnLock',
    );

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

    return 1 if $Param{Event} ne 'TicketLockUpdate'; 

    my $TicketID = $Param{TicketID};

    $Self->{LogObject}->Log(
        Priority => 'error',
        Message => 'SetStateOnLock - Ticket: ' . $TicketID,
    );

    my %TicketData = $Self->{TicketObject}->TicketGet(
        TicketID => $TicketID,
    );

    $Self->{LogObject}->Log(
        Priority => 'error',
        Message => 'Run SetStateOnLock - new Lockstate: ' . $TicketData{Lock},
    );

    return 1 if $TicketData{Lock} ne 'lock'; # set new state only if ticket is locked now

    $Self->{TicketObject}->StateSet( # StateSet is 2.x method, in 3.x it is TicketStateSet
        TicketID => $TicketID,
        UserID => 1,
        State => 'Work In Progress',
    );

    return 1;
}

1;
Then do the following:

Code: Select all

cd /opt/otrs/
perl -IKernel/cpan-lib/ -cw Kernel/System/Ticket/Event/SetStateOnLock.pm
If the result is "Syntax ok", the module should be triggered.

Then you should tail the log (tail -f /path/to/otrs.log)
Need a Perl/OTRS developer? You can contact me at info@perl-services.de
abhijitsarangi
Znuny newbie
Posts: 12
Joined: 21 Feb 2011, 08:19
Znuny Version: otrs-2.4.7-01

Re: How to Chnage Ticket Status when ticket is Locked

Post by abhijitsarangi »

Yes have made changes and the code

Code: Select all

perl -IKernel/cpan-lib/ -cw Kernel/System/Ticket/Event/SetStateOnLock.pm
gives O/P Syntax is Ok

but the syslog message i;e the /var/log/message gives O/P as

Code: Select all

Aug 10 14:33:21 ************** OTRS-CGI-10[11484]: [Error][Kernel::System::Ticket::Event::SetStateOnLock::Run][Line:41]: Run SetStateOnLock
Aug 10 14:33:21 ************** OTRS-CGI-10[11484]: [Error][Kernel::System::Ticket::Event::SetStateOnLock::Run][Line:49]: Need Data!
Aug 10 14:33:26 ************** OTRS-CGI-10[11516]: [Error][Kernel::System::Ticket::Event::SetStateOnLock::Run][Line:41]: Run SetStateOnLock
Aug 10 14:33:26 ************** OTRS-CGI-10[11516]: [Error][Kernel::System::Ticket::Event::SetStateOnLock::Run][Line:49]: Need Data!
renee
Znuny expert
Posts: 241
Joined: 06 Feb 2009, 11:15
Znuny Version: 3.0.x
Company: Perl-Services.de
Contact:

Re: How to Chnage Ticket Status when ticket is Locked

Post by renee »

Replace

Code: Select all

for (qw(Event Data Config UserID)) {
with

Code: Select all

for (qw(Event UserID TicketID)) {
and try it again...
Need a Perl/OTRS developer? You can contact me at info@perl-services.de
abhijitsarangi
Znuny newbie
Posts: 12
Joined: 21 Feb 2011, 08:19
Znuny Version: otrs-2.4.7-01

Re: How to Chnage Ticket Status when ticket is Locked

Post by abhijitsarangi »

Thanks a lot Renee... Thant worked.... Thanks for the great support and guidance...
abhijitsarangi
Znuny newbie
Posts: 12
Joined: 21 Feb 2011, 08:19
Znuny Version: otrs-2.4.7-01

Re: How to Chnage Ticket Status when ticket is Locked

Post by abhijitsarangi »

Dear Renne,

Now If I would like to achieve the objective of " if ticket state is closed then it should automatically get Unlocked" . Where do I need to modify.. in ForceState.pm or in ForceUnlock.pm or the SetStateOnLock.pm can be modified to achieve the same????
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: How to Chnage Ticket Status when ticket is Locked

Post by crythias »

That should happen upon close.
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
Locked