Need help to write a searchbuilder query for RT 3

Hello,

I need some initial example to understand how searchbuilder queries are
written.

Can anyone help me with the following:

given a User, I want to have a list of all tickets, which have no owner and
are in a queue, where the given user has Right “OwnTicket”.

Since this needs Limit and Join, this will hopefully help me to understand
the systematics to invent further searches by by own.

Thank you,
Dirk.

Hello,

I did not get an answer to my question. Can anybody point me to useful
documentaion instead.

Thanks,
Dirk

–Am Freitag, 8. August 2003 10:32 Uhr +0200 schrieb Dirk Pape
pape-rt@inf.fu-berlin.de:

given a User, I want to have a list of all tickets, which have no owner
and are in a queue, where the given user has Right “OwnTicket”.

Since this needs Limit and Join, this will hopefully help me to
understand the systematics to invent further searches by by own.

There are two issues.

  • Joining requires knowledge of the database structure as the RT Classes
    do not support joins.
  • Evaluating a right requires more than a table join, I doubt that you
    can create a single database query to evaluate a right. But maybe
    Jesse knows some magic trick :slight_smile:

So I suggest to do one database query to find all tickets that belong
to a given queue and that have no owner (== are owned by the Nobody user).

Then, for each ticket you check if the given user has the right to own
the ticket.

Here is an example script:

use RT;
use RT::User;
use RT::Queue;
use RT::Tickets;

hiding in dark places

$RT::LogDir = ‘/tmp’;
$RT::LogToFileNamed = ‘/dev/null’;

RT::LoadConfig();
RT::Init();

operate as superuser

my $cuser = $RT::SystemUser;

create a user object and load it with data for the given user name

my $nuser = new RT::User($cuser);
$nuser->Load(‘given-user-name’);

create a queue object and load it with data for the given queue name

my $q = new RT::Queue($cuser);
$q->Load(‘given-queue-name’);

create tickets collection object

my $ts = new RT::Tickets($cuser);

select tickets that belong to nobody and belong to the given queue

$ts->LimitOwner( VALUE => $RT::Nobody->Id );
$ts->LimitQueue( VALUE => $q->Id );

fetch results

my $items = $ts->ItemsArrayRef || ;

foreach my $t (@$items) {
# verify ticket rights
if ($t->HasRight( Principal => $nuser,
Right => ‘OwnTicket’ )) {
print $t->Id," YEAH\n";
} else {
print $t->Id," NEY\n";
}
}

Greetings,
,eM"“=. a”-. Michael van Elst
dWWMWM" - :GM==; mlelstv@dev.de.cw.net
:WWMWMw=–. "W=’ cable & wireless
9WWMm==-.
“-Wmw-” CABLE & WIRELESS