Question about sql limits

Good day.

In RT code many constructions like $self->TicketsObj->Limit* - limit sql query in some params.
I try use construction
$self->TicketsObj->LimitPriority(VALUE => “FinalPriority”, OPERATOR => “<”);

and finally sql code look like this:

…AND ( ‘Priority’ < ‘FinalPriority’ )

But I can’t understand how get sql code like this

AND ( ‘Priority’ < FinalPriority )

Can someone help?

Something like this? $self->TicketsObj->LimitPriority(VALUE => $self->TicketsObj->FinalPriority, OPERATOR => "<");

may be, but I see error:
Can’t locate object method “FinalPriority” via package “RT::Tickets”

Where are you trying to do this? You want to use the TicketObj since you should only be checking the final priority for one ticket

I’m trying next:

package RT::Search::ActivePriorityTicketsInQueue;

use strict;
use warnings;
use base qw(RT::Search);

sub Describe {
my $self = shift;
return ($self->loc(“No description for [_1]”, ref $self));

sub Prepare {
my $self = shift;

$self->TicketsObj->LimitPriority(VALUE => $self->TicketsObj->FinalPriority, OPERATOR => “<”);




and exec that in

rt-crontool --search RT::Search::ActivePriorityTicketsInQueue --action RT::Action::EscalatePriority

I think it’d be better to make a new action /local/lib/RT/ where you copy the content of EscalatePriority but add a check to see if the action should run based on the Final priority of the ticket

I would like to limit the search in the database and not filter the result in RT.
In ActivePriorityTicketsInQueue I can use

$self->TicketsObj->LimitFinalPriority(VALUE => 1, OPERATOR => “>”);

and found tickets that used priority. But this search will also include tickets with Priority==FinalPriority and you will need to drop them into action.


select id from Tickets where (Status = ‘open’ OR Status = ‘new’ OR Status = ‘stalled’) and ‘Priority’ < FinalPriority;

do what I want. How to generate this sql in RT code?

You can try using the RT::Search::FromSQL module but I don’t know if you can use two variable values like that but its worth a try

I tried this module:

$self->TicketsObj->FromSQL("( Status = ‘open’ OR Status = ‘new’ OR Status = ‘stalled’ ) AND ( Priority < FinalPriority )");

and got the error:

Couldn’t parse query: Wrong query, expecting a VALUE in ‘( Status = ‘open’ OR Status = ‘new’ OR Status = ‘stalled’ ) AND ( Priority < >FinalPriority<–here )’ at /
opt/rt4/bin/…/lib/RT/ line 3036, line 522. (/opt/rt4/bin/…/lib/RT/

I see there appears to be a branch on Github:

Yes, because there is a typo in the code. It should be:

$self->TicketsObj->LimitPriority(VALUE => $self->TicketObj->FinalPriority, OPERATOR => "<");


Can’t locate object method “TicketObj” via package “RT::Search::ActivePriorityTicketsInQueue”