Hello
I have fixed the issue. The problem was that I was using mixed code of version 3 and 4. Also the code was looking for parameters that could only be get on the run routine.
Everything looks ok based on the logs that I'm triggering. But the value of the dynamic field is not showing on the tickets list displayed in the queue view.
Could anyone give me a hint on the possible causes?
Here goes the correct code and the logs triggered by it:
Code: Select all
# --
# Store Original Queue on Dynamic Field
# --
package Kernel::System::Ticket::Event::CreatedInQueue;
use strict;
use warnings;
use Kernel::System::DynamicField;
use Kernel::System::DynamicField::Backend;
use Kernel::System::VariableCheck qw(:all);
our @ObjectDependencies = (
'Kernel::System::Log',
'Kernel::System::Ticket',
'Kernel::System::DynamicField::Backend'
);
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {};
bless( $Self, $Type );
return $Self;
}
sub Run {
my ( $Self, %Param ) = @_;
#$Kernel::OM->Get('Kernel::System::Log')->Dumper($Param{Data});
#$Kernel::OM->Get('Kernel::System::Log')->Dumper($Param);
# Check needed parameters
for(qw(Data Event Config)){
if(!$Param{$_}){
$Kernel::OM->Get('Kernel::System::Log')->Log(Priority => 'error', Message => "Need $_!");
}
}
if ( $Param{Event} eq 'TicketCreate' ) {
# Get ticket base object
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
# Get created ticket object
my %Ticket = $TicketObject->TicketGet(
TicketID => $Param{Data}->{TicketID},
DynamicFields => 0,
);
# Get dyn field config of InitQueue
my $DynamicFieldConfig = $Kernel::OM->Get('Kernel::System::DynamicField')->DynamicFieldGet(Name => 'InitQueue');
# Set the value of InitQueue for the created ticket
my $Success = $Kernel::OM->Get('Kernel::System::DynamicField::Backend')->ValueSet(
DynamicFieldConfig => $DynamicFieldConfig,
ObjectID => $Ticket{TicketID},
Value => "THE_VALUE:: $Ticket{Queue}",
UserID => $Param{UserID}
);
# Debug
$Kernel::OM->Get('Kernel::System::Log')->Log(Priority => 'info', Message => "$Ticket{TicketID}");
$Kernel::OM->Get('Kernel::System::Log')->Log(Priority => 'info', Message => "The UserID: $Param{UserID}");
$Kernel::OM->Get('Kernel::System::Log')->Log(Priority => 'info', Message => "Success: $Success");
$Kernel::OM->Get('Kernel::System::Log')->Log(Priority => 'info', Message => "TICKET QUEUE: $Ticket{Queue}");
}
return 1;
}
1;
The Logs:
[Fri Aug 12 09:59:30 2016][Info][Kernel::System::Ticket::Event::CreatedInQueue::Run] 105
[Fri Aug 12 09:59:30 2016][Info][Kernel::System::Ticket::Event::CreatedInQueue::Run] The UserID: 1
[Fri Aug 12 09:59:30 2016][Info][Kernel::System::Ticket::Event::CreatedInQueue::Run] Success: 1
[Fri Aug 12 09:59:30 2016][Info][Kernel::System::Ticket::Event::CreatedInQueue::Run] TICKET QUEUE: Raw