[rt-users] getting username from id

Mathew theillien at yahoo.com
Fri Mar 30 13:06:33 EDT 2007


Ruslan Zakirov wrote:
> On 3/30/07, Mathew <theillien at yahoo.com> wrote:
>> Ruslan Zakirov wrote:
>> > 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.
>>
>> But If I don't use it I get all the users.  Even watchers.  I just want
>> the users that we have internally.  These are the only people we're
>> concerned about as far as time worked goes.
> 
> see comment below.
> 
>>
>> >
>> >>
>> >> while (my $ticket = $tix->Next) {
>> >>     my $environment = $ticket->FirstCustomFieldValue('Environment');
>> >>     my $user;
>> > this ^^^ line is also useless
>>
>> Yeah, I forgot to remove that before I posted.  I got rid of it in the
>> actual script when I realized it is redundant.
>>
>> >
>> >>     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;
>>
>> Which block specifically?  The while (my $user = $users->Next) block?
> yes.
> 
> If you're interested in privileged users only then you can use something
> like:
> next unless $creator_obj->Privileged;

Ah.  Excellent.  Thanks.

> 
> 
>>
>> >
>> >>     }
>> >> }
>> >>
>> >> 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
>> >>
>> >
>> >
>>
>>
>> Thank you all for the help.  I do seriously appreciate it.
>>
>> Mathew
>>
> 
> 

Mathew



More information about the rt-users mailing list