[rt-users] RT 4.0.2: Custom Condition Fails

Ryan Frantz ryanfrantz at informed-llc.com
Thu Oct 13 22:35:40 EDT 2011


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 



I used the following Perl script to register the condition within RT: 


use strict; 

use lib "/usr/local/rt/lib"; 

use RT; 

use RT::Interface::CLI qw( CleanEnv GetCurrentUser ); 

use RT::ScripCondition; 




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? 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20111013/60fe2e88/attachment.htm>

More information about the rt-users mailing list