[rt-users] getting username from id
Ruslan Zakirov
ruslan.zakirov at gmail.com
Fri Mar 30 11:09:05 EDT 2007
On 3/29/07, Mathew Snyder <theillien at yahoo.com> wrote:
> 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;
delete this you don't need it.
>
> while (my $ticket = $tix->Next) {
> my $environment = $ticket->FirstCustomFieldValue('Environment');
> my $user;
this ^^^ line is also useless
> 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};
> }
instead of above block use the following code:
my $creator = $transactions->CreatorObj;
$timeworked{ $creator->Name } += $transaction->TimeTaken;
$environment{$environment}{ $creator->Name } +=
$transaction->TimeTaken;
> }
> }
>
> 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
> _______________________________________________
> http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
>
> Community help: http://wiki.bestpractical.com
> Commercial support: sales at bestpractical.com
>
>
> Discover RT's hidden secrets with RT Essentials from O'Reilly Media.
> Buy a copy at http://rtbook.bestpractical.com
>
--
Best regards, Ruslan.
More information about the rt-users
mailing list