List,
I recently created a custom condition to match tickets created after hours so
that I could use it in a scrip to send a copy of the ticket information to the
on-call Support Desk tech. I first tested it successfully on an old RT 3.8.8
installation and then started testing it in my RT 4.0.2 installation. I get
the following error:
Oct 13 22:20:57 rt2 RT: Scrip IsApplicable 14 died. - Can't locate object
method "new" via package "RT::Condition::OnAfterHoursCreate" at
/usr/local/rt/sbin/../lib/RT/ScripCondition.pm line 173. Stack:
[/usr/local/rt/sbin/../lib/RT/ScripCondition.pm:173]
[/usr/local/rt/sbin/../lib/RT/Scrip.pm:404]
[/usr/local/rt/sbin/../lib/RT/Scrips.pm:225]
[/usr/local/rt/sbin/../lib/RT/Transaction.pm:179]
[/usr/local/rt/sbin/../lib/RT/Record.pm:1447]
[/usr/local/rt/sbin/../lib/RT/Ticket.pm:669]
[/usr/local/rt/sbin/../lib/RT/Interface/Web.pm:1389]
[/usr/local/rt/share/html/Ticket/Display.html:127]
[/usr/local/rt/share/html/Ticket/Create.html:444]
[/usr/local/rt/sbin/../lib/RT/Interface/Web.pm:538]
[/usr/local/rt/sbin/../lib/RT/Interface/Web.pm:285]
[/usr/local/rt/share/html/autohandler:53]
(/usr/local/rt/sbin/../lib/RT/Scrip.pm:419)
The name of the custom condition is OnAfterHoursCreate and it is located under
<myRtRoot>/local/lib/RT/Condition/. What's odd is that when I look at the
system condition modules, I don't see a new() method defined so I'm not sure
why this error is occuring for me. For reference, this is the code for the
custom condition:
package RT::Condition::OnAfterHoursCreate;
use warnings;
use strict;
use base 'RT::Condition';
sub IsApplicable {
my $self = shift;
my $weekday = (localtime)[6];
my $min = (localtime)[1];
my $hour = (localtime)[2];
return 1 if $weekday == 6 || $weekday == 0;
return 1 if $hour >= 17 || ( $hour <= 8 && $min <= 29);
return 0; # no match
}
1;
I used the following Perl script to register the condition within RT:
#!/usr/bin/perl
use strict;
use lib "/usr/local/rt/lib";
use RT;
use RT::Interface::CLI qw( CleanEnv GetCurrentUser );
use RT::ScripCondition;
CleanEnv();
RT::LoadConfig();
RT::Init();
my $user = GetCurrentUser();
unless( $user->Id ) {
print "No RT user found. Please consult your RT administrator.\n";
exit 1;
}
my $sc = RT::ScripCondition->new($user);
$sc->Create( Name => 'On After Hours Create',
Description => 'A ticket is created after hours',
ExecModule => 'OnAfterHoursCreate',
ApplicableTransTypes => 'Create',
);
I built the custom condition and registration code from an example I found in
the 'RT Essentials' book published by O'Reilly. In fact, it's a 99% lift from
that book. The only difference I noted that was required for custom conditions
in RT 4 was the need to change "use base 'RT::Condition:Generic';" to "use base
'RT::Condition';".
Am I missing something in general? Or am I missing something specific to RT 4?
Ryan
--------
RT Training Sessions (http://bestpractical.com/services/training.html)
* San Francisco, CA, USA October 18 & 19, 2011
* Washington DC, USA October 31 & November 1, 2011
* Barcelona, Spain November 28 & 29, 2011