More snippets are available on official wiki.
Important: All snippets here must begin with this the init code described in general.md file.
my $queue = RT::Queue->new(RT->SystemUser);
$queue->Load('My Queue Name');
p $queue;
my $cf1 = RT::CustomField->new(RT->SystemUser);
$cf1->LoadByName(Name => 'cf1');
my $ticket = RT::Ticket->new(RT->SystemUser);
$ticket->Load(12); # Load by id
my $value = $ticket->FirstCustomFieldValue('My CF name');
my $ticket = RT::Ticket->new(RT->SystemUser);
$ticket->Load(12); # Load by id
$ticket->AddCustomFieldValue(Field => 'My CF name', Value => 'My value');
my $queueName = 'My Queue';
my $tickets = RT::Tickets->new(RT->SystemUser); # RT::Tickets instance
$tickets->LimitQueue(VALUE => $queueName);
print $tickets->Count . " tickets founds in queue '" . $queueName . "':\n";
while (my $ticket = $tickets->Next()) {
# $ticket is an RT::Ticket instance
print " - #" . $ticket->Id . ": " . $ticket->Subject . "\n";
}
my $groups = RT::Groups->new(RT->SystemUser);
$groups->LimitToUserDefinedGroups;
while (my $group = $groups->Next) {
print $group->Name . "\n";
}