Skip to content

Latest commit

 

History

History
59 lines (45 loc) · 1.42 KB

snippets.md

File metadata and controls

59 lines (45 loc) · 1.42 KB

Loading objects

More snippets are available on official wiki.

Important: All snippets here must begin with this the init code described in general.md file.

Load a Queue

my $queue = RT::Queue->new(RT->SystemUser);
$queue->Load('My Queue Name');
p $queue;

Load a Custom field

my $cf1 = RT::CustomField->new(RT->SystemUser);
$cf1->LoadByName(Name => 'cf1');

Get a CF value for a ticket

my $ticket = RT::Ticket->new(RT->SystemUser);
$ticket->Load(12);  # Load by id
my $value = $ticket->FirstCustomFieldValue('My CF name');

Set a CF value for a ticket

my $ticket = RT::Ticket->new(RT->SystemUser);
$ticket->Load(12);  # Load by id
$ticket->AddCustomFieldValue(Field => 'My CF name', Value => 'My value');

List tickets in a queue

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";
}

List user-defined groups

my $groups = RT::Groups->new(RT->SystemUser);
$groups->LimitToUserDefinedGroups;
while (my $group = $groups->Next) {
    print $group->Name . "\n";
}