Would like to modify the Date.pm ticket module so that the format would read as follows: YearMonthDay-3digit number (20120725-001
Would like to have the hyphen and the 3 digit number auto increment and reset every new day. Anyone know what the code change would be?
# --
# Ticket/Number/Date.pm - a date ticket number generator
# Copyright (C) 2001-2009 xxx, http://otrs.org/
# --
# $Id: Date.pm,v 1.31 2009/05/15 10:12:02 martin 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.
# --
# Note:
# available objects are: ConfigObject, LogObject and DBObject
#
# Generates ticket numbers like yyyymmddss.... (e. g. 200206231010138)
# --
package Kernel::System::Ticket::Number::Date;
use strict;
use warnings;
use vars qw($VERSION);
$VERSION = qw($Revision: 1.31 $) [1];
sub TicketCreateNumber {
my ( $Self, $JumpCounter ) = @_;
if ( !$JumpCounter ) {
$JumpCounter = 0;
}
# get needed config options
my $CounterLog = $Self->{ConfigObject}->Get('Ticket::CounterLog');
my $SystemID = $Self->{ConfigObject}->Get('SystemID');
# get current time
my ( $Sec, $Min, $Hour, $Day, $Month, $Year ) = $Self->{TimeObject}->SystemTime2Date(
SystemTime => $Self->{TimeObject}->SystemTime(),
);
# read count
my $Count = 0;
if ( -f $CounterLog ) {
my $ContentSCALARRef = $Self->{MainObject}->FileRead(
Location => $CounterLog,
);
if ( $ContentSCALARRef && ${$ContentSCALARRef} ) {
($Count) = split( /;/, ${$ContentSCALARRef} );
# just debug
if ( $Self->{Debug} > 0 ) {
$Self->{LogObject}->Log(
Priority => 'debug',
Message => "Read counter from $CounterLog: $Count",
);
}
}
}
# count auto increment ($Count++)
$Count++;
$Count = $Count + $JumpCounter;
# write new count
my $Write = $Self->{MainObject}->FileWrite(
Location => $CounterLog,
Content => \$Count,
);
if ($Write) {
if ( $Self->{Debug} > 0 ) {
$Self->{LogObject}->Log(
Priority => 'debug',
Message => "Write counter: $Count",
);
}
}
# create new ticket number
my $Tn = $Year . $Month . $Day . $SystemID . $Count;
# Check ticket number. If exists generate new one!
if ( $Self->TicketCheckNumber( Tn => $Tn ) ) {
$Self->{LoopProtectionCounter}++;
if ( $Self->{LoopProtectionCounter} >= 16000 ) {
# loop protection
$Self->{LogObject}->Log(
Priority => 'error',
Message => "CounterLoopProtection is now $Self->{LoopProtectionCounter}!"
. " Stopped TicketCreateNumber()!",
);
return;
}
# create new ticket number again
$Self->{LogObject}->Log(
Priority => 'notice',
Message => "Tn ($Tn) exists! Creating a new one.",
);
$Tn = $Self->TicketCreateNumber( $Self->{LoopProtectionCounter} );
}
return $Tn;
}
sub GetTNByString {
my ( $Self, $String ) = @_;
if ( !$String ) {
return;
}
# get needed config options
my $CheckSystemID = $Self->{ConfigObject}->Get('Ticket::NumberGenerator::CheckSystemID');
my $SystemID = '';
if ($CheckSystemID) {
$SystemID = $Self->{ConfigObject}->Get('SystemID');
}
my $TicketHook = $Self->{ConfigObject}->Get('Ticket::Hook');
my $TicketHookDivider = $Self->{ConfigObject}->Get('Ticket::HookDivider');
# check current setting
if ( $String =~ /\Q$TicketHook$TicketHookDivider\E(\d{4,10}$SystemID\d{1,40})/i ) {
return $1;
}
# check default setting
if ( $String =~ /\Q$TicketHook\E:\s{0,2}(\d{4,10}$SystemID\d{1,40})/i ) {
return $1;
}
return;
}
1;
Modify ticket number module
Moderator: crythias
Re: Modify ticket number module
Please don't ask Questions in How To section!
"Production": OTRS™ 8, OTRS™ 7, STORM powered by OTRS
"Testing": ((OTRS Community Edition)) and git Master
Never change Defaults.pm! :: Blog
Professional Services:: http://www.otrs.com :: enjoy@otrs.com
"Testing": ((OTRS Community Edition)) and git Master
Never change Defaults.pm! :: Blog
Professional Services:: http://www.otrs.com :: enjoy@otrs.com
-
- Znuny newbie
- Posts: 21
- Joined: 07 Dec 2011, 22:47
- Znuny Version: 3.0.11
- Real Name: Malcolm Bartlett
- Company: CANARIE
- Location: Ottawa, ON, Canada
- Contact:
Re: Modify ticket number module
So I figured out most of my questions except for two. The ticket number now shows up as 20120725-4 and auto increments.
How do I get it to show up with leading zeros. 20120725-004 ?
Also, how do I get the counter to reset each day ?
Malcolm
How do I get it to show up with leading zeros. 20120725-004 ?
Also, how do I get the counter to reset each day ?
Malcolm
-
- Znuny newbie
- Posts: 21
- Joined: 07 Dec 2011, 22:47
- Znuny Version: 3.0.11
- Real Name: Malcolm Bartlett
- Company: CANARIE
- Location: Ottawa, ON, Canada
- Contact:
Re: Modify ticket number module
Ok, so I figured out the zeros. Now I would like to remove the SystemID. I did figure this out by removing it from this line in the Date.pm file:
my $Tn = $Year . $Month . $Day . $SystemID . $Count;
is now
my $Tn = $Year . $Month . $Day . $Count;
But whenever I sent an email update it now creates a new ticket with a new ticket number. If i put it back in then the ticket update goes into the original ticket.
Still haven't got the counter to reset each day either.
my $Tn = $Year . $Month . $Day . $SystemID . $Count;
is now
my $Tn = $Year . $Month . $Day . $Count;
But whenever I sent an email update it now creates a new ticket with a new ticket number. If i put it back in then the ticket update goes into the original ticket.
Still haven't got the counter to reset each day either.
-
- Moderator
- Posts: 10170
- Joined: 04 May 2010, 18:38
- Znuny Version: 5.0.x
- Location: SouthWest Florida, USA
- Contact:
Re: Modify ticket number module
SystemID is important if you don't want ticket collisions between OTRS installs. If you don't want/need that, then disable SystemID check in 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
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