[rt-devel] Problems using LimitXXX Statements

Julian Hein jhein at netways.de
Mon Jan 28 19:49:06 EST 2002

Hi everybody,

I am having problems with LimitKeyword and LimitDate statements when
using them in reports or cronjobs to generate mail. Here are the two

1) I was trying to write a report component, that gives me back the
of tickets, that are having a specific keyword assigned to them, but I
did not succeed. All I managed is to get either the total number of
tickets or zero.

I set up the keyword tree like this and assigned the keyword tree
global, single childs. =20


Afterwards i looked in the SQL Table KeywordSelects, for the Id to use
in LimitKeyword. Then I used this code:

my $num=3D0;
my $open =3D new RT::Tickets($session{'CurrentUser'});

$open->LimitStatus(VALUE =3D> 'resolved');
$open->LimitStatus(VALUE =3D> 'open');
$open->LimitStatus(VALUE =3D> 'new');

$open->LimitKeyword(KEYWORD =3D> 2, OPERATOR =3D> 'IS', KEYWORDSELECT =
=3D> 1);
$open->OrderBy(FIELD =3D> 'Created', ORDER =3D> 'asc');

$num =3D $open->Count();


2) The second thing was a script the should be run by cron and send a
mail to every user owning at ticket with a due date of today. I modified
tickets to very date one could think of and user all operators (=><) but
i allways got the same tickets or no ticket. Any ideas?

use strict;
use Carp;

use lib "/opt/rt2/lib";
use lib "/opt/rt2/etc";

use RT::Interface::CLI  qw(CleanEnv LoadConfig DBConnect 
                           GetCurrentUser GetMessageContent);

#Clean out all the nasties from the environment

#Load etc/config.pm and drop privs

#Connect to the database and get RT::SystemUser and RT::Nobody loaded

use RT::Date;
use RT::Tickets;

my $now = new RT::Date($RT::SystemUser);

my $tickets = new RT::Tickets($RT::SystemUser);
$tickets->LimitStatus(VALUE => 'open');
$tickets->LimitStatus(VALUE => 'new');
$tickets->LimitStatus(VALUE => 'stalled');
$tickets->LimitDate(FIELD => 'Due', OPERATOR => '=', VALUE => $now);

while (my $ticket = $tickets->Next) {

        open(MAIL,"|/usr/sbin/sendmail -t");   
        print MAIL $ticket->Id."\n";
        print MAIL "X-Priority: 1\n";
        print MAIL "Priority: Urgent\n";
        print MAIL "Importance: high\n";
        print MAIL "From:\n";
        print MAIL "To:jhein\@netways.de\n";
        print MAIL "Subject: [netways #".$ticket->Id."] Ticket
        print MAIL "The following ticket has reached its due date.
Please resolve imediatly!\n\n";
        print MAIL "    Ticket: [netways #".$ticket->Id."]\n";
        print MAIL "     Queue: ".$ticket->QueueObj->Name."\n";
        print MAIL "   Subject: ".$ticket->Subject."\n";
        print MAIL "     Owner: ".$ticket->OwnerAsString."\n";
        print MAIL " Requestor:
        print MAIL "Ticket URL:
        print MAIL "   DueDate: ".$ticket->Due."\n";


Thanks a lot, Julian
Julian Hein                   NETWAYS GmbH
Managing Director             Deutschherrnstr. 47a
Fon.0911/92885-0              D-90429 Nürnberg
jhein at netways.de              www.netways.de              

More information about the Rt-devel mailing list