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
At Thursday 3/29/2007 04:28 AM, Mathew Snyder wrote:
while (my $user = $users->Next) {
if ($user = $transaction->Creator) {
$timeworked{$user} += $transaction->TimeTaken;
}
$environment{$environment}{$user->Name} = $timeworked{$user};
}
In the if statement, you are setting $user to $transaction->Creator,
which is an integer. So $user is no longer a User object and hence no
Name method.
Also, a comment - in looking at the code I did get confused by the
dual use of “environment” to represent a scalar variable and a hash -
might be better for code maintenance to choose different names.
Steve
At Thursday 3/29/2007 04:28 AM, Mathew Snyder wrote:
while (my $user = $users->Next) {
if ($user = $transaction->Creator) {
also here ^^^^
you use ‘=’ which equality operator not a ‘==’ boolean operator which
compares numeric values, so you overwrite value in $user variable. you
need the following condition:
if ( $user->id == $transaction->Creator ) {
…
$timeworked{$user} += $transaction->TimeTaken;
}
$environment{$environment}{$user->Name} = $timeworked{$user};
}
In the if statement, you are setting $user to $transaction->Creator,
which is an integer. So $user is no longer a User object and hence no
Name method.
However, there is $transaction->CreatorObj method that returns user’s object.
Also, a comment - in looking at the code I did get confused by the
dual use of “environment” to represent a scalar variable and a hash -
might be better for code maintenance to choose different names.
Steve
The rt-users Archives
Community help: http://wiki.bestpractical.com
Commercial support: sales@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.
Best regards, Ruslan.
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
The rt-users Archives
Community help: http://wiki.bestpractical.com
Commercial support: sales@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.
Ruslan Zakirov 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.
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?
}
}
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
The rt-users Archives
Community help: http://wiki.bestpractical.com
Commercial support: sales@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
Ruslan Zakirov 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;
}
}
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
The rt-users Archives
Community help: http://wiki.bestpractical.com
Commercial support: sales@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
Best regards, Ruslan.
Ruslan,
I made the changes you suggested and after a bit of tinkering everything works
well. However, I’m trying to format the time worked as hh:mm. This is the
block of code I’m using:
foreach my $enviro (keys %environment) {
my $user;
my %wholetime;
foreach $user (keys %timeworked) {
my @endTime;
my $temp = $timeworked{$user};
print “Temp -> $temp\n”;
my $check = $temp / 60;
print $check . “\n”;
my @temp = split /./, $check;
$endTime[0] = $temp[0];
$endTime[1] = $timeworked{$user} % 60;
$wholetime{$user} = sprintf ‘%d:%02d’, @endTime[0,1];
$environment{$enviro}{$user} = $wholetime{$user};
}
}
A couple of interesting things is happening. One is that the time is staying in
minutes with no formatting. The second and most bizarre is that the two ‘print’
statements aren’t doing anything. $temp is printing in the line that says
’print “Temp -> $temp” . “\n”;’ but that’s it. "Temp -> " isn’t printing. And
the line that says ‘print $check;’ doesn’t do anything. No output whatsoever.
I can’t for the life of me figure out why it is behaving the way it is as I’ve
compared it to near identical code in another script and it appears to be as it
should. Is there anything you see that seems out of the ordinary?
Thanks again,
Mathew
Ach!!
Disregard my last help request. I figured it out
Mathew
Mathew Snyder wrote: