[rt-users] getting username from id

Mathew Snyder theillien at yahoo.com
Thu Mar 29 04:28:15 EDT 2007


I've been working on a script for a while and finally have it working more or
less the way I need it to.  The last thing (besides file formatting) is to get
the usernames.  I'm getting the users via LimitToPrivileged in Users.pm.  In
another script I proved to myself that I can get the names using the ->Name method:

my $users = new RT::Users(RT::SystemUser);
$users->LimitToPrivileged;

while ( my $user = $users->Next ) {
        next if $user->Name eq 'root';
        print $user->Name . "\n";
}

exit;

However, when I try to use the same method to populate a hash I get the error
indicating "Can't call method "Name" without a package or object reference at
./user_timesheet_3.pl line 65."

This is the block of code in contention:

my $users = new RT::Users(RT::SystemUser);
$users->LimitToPrivileged;

while (my $ticket = $tix->Next) {
    my $environment = $ticket->FirstCustomFieldValue('Environment');
    my $user;
    unless ($environment) {
        warn "warning " . $ticket->id. " has no environment";
             next
    }

    my $transactions = $ticket->Transactions;
    while (my $transaction = $transactions->Next) {
        next unless ($transaction->TimeTaken);
        while (my $user = $users->Next) {
            if ($user = $transaction->Creator) {
                $timeworked{$user} += $transaction->TimeTaken;
            }
            $environment{$environment}{$user->Name} = $timeworked{$user};
        }
    }
}

foreach my $key (sort keys %environment) {
        print $key, "\n";
        print ("-" x 15);
        print "\n";
        foreach my $key2 (keys %{ $environment{$key} }) {
                print "$key2 -> $environment{$key}{$key2}\n";
        }
        print "\n";
}

Can anyone help me correct this?

Mathew



More information about the rt-users mailing list