[rt-users] Pulling CustomFieldValues

Şubredu Manuel diablo at iasi.roedu.net
Wed Nov 29 06:47:37 EST 2006


> Steve,
> 
> This is the code I now have:
> #!/usr/bin/perl
> use warnings;
> use strict;
> use lib "/usr/local/rt-3.6.1/lib";
> use RT;
> use RT::CustomField;
> use RT::Interface::CLI qw(CleanEnv);
> 
> CleanEnv();
> RT::LoadConfig();
> RT::Init();
> my $cf_name = "Profiles";
> 
> my $cf = RT::CustomField->new(RT::SystemUser);
> $cf->Values($cf_name);
> foreach my $cf_key (${cf}){
>         print $$cf_key{"KEY"} . "\n";
> };
> exit;
> 
> Values() appears to return a reference to a hash.  If I run this code I get one
> blank line back.  I guess I don't know how to iterate through the hash to print
> out each item.  How would I go about that?

 There is something wrong here. What does $cf->Values returns ? Maybe
you should try to use Data::Dumper to see exactly what you have there.

  use Data::Dumper;

  <code>
  print Dumper($cf->Values($cf_name);
  <code>

 btw, the 'right way' to print a hash values is:

 foreach(keys(%{ $cf })) {
  my $item = $_;

  print $item,q{:},$cf->{$item},$/;
 }

 I guess this little code is more readable than the other one :)

> 
> 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



More information about the rt-users mailing list