Mathew Snyder wrote:
> I need to get a list of all of the values for one particular custom field.  I
> had a script which did this after about a week or two of banging my head 
> against
> my desk.  However, I no longer have this script and am left banging my head
> again as I've forgotten how to gather this list up.
> 
> I've tried using CustomFieldValue, CustomFieldValues, CustomField and
> CustomFields.  I can't for the life of me figure out how to do this.  Can
> someone point me in the right direction?
> 

This is what I'm working with:
#!/usr/bin/perl

use warnings;
use strict;
use lib '/usr/local/rt3/lib';
use lib '/usr/local/rt3/local/lib';
use RT;
use RT::Users;

RT::LoadConfig(); ## Loading RT config
RT::Init(); ## Initialise RT

my $cf_name = "Environment";
my @envs;

my $cf = RT::CustomFieldValues->new(RT::SystemUser);
$cf->LimitToCustomField($cf_name);

while (my $cfval = $cf->Next() ){
   print $cfval->Name . "\n";
};

Using Data::Dumper I have the following output:
$VAR1 = bless( {
                 '_open_parens' => {},
                 'alias_count' => 0,
                 'where_clause' => '',
                 'order_by' => [
                                 {
                                   'ORDER' => 'ASC',
                                   'FIELD' => 'SortOrder',
                                   'ALIAS' => 'main'
                                 },
                                 {
                                   'ORDER' => 'ASC',
                                   'FIELD' => 'Name',
                                   'ALIAS' => 'main'
                                 },
                                 {
                                   'ORDER' => 'ASC',
                                   'FIELD' => 'id',
                                   'ALIAS' => 'main'
                                 }
                               ],
                 'table' => 'CustomFieldValues',
                 'tables' => '',
                 'is_limited' => 1,
                 'order' => '',
                 'user' => bless( {
                                    '_Class' => 'RT::CurrentUser',
                                    '_SB_Record_Primary_RecordCache_key' => 
'id=1',
                                    'table' => 'Users',
                                    'values' => {
                                                  'creator' => '1',
                                                  'comments' => 'Do not delete
or modify this user. It is integral to RT\'s internal database structures',
                                                  'state' => undef,
                                                  'webencoding' => undef,
                                                  'realname' => 'The RT System
itself',
                                                  'password' => '*NO-PASSWORD*',
                                                  'authsystem' => undef,
                                                  'homephone' => undef,
                                                  'id' => '1',
                                                  'timezone' => undef,
                                                  'lang' => undef,
                                                  'name' => 'RT_System',
                                                  'contactinfosystem' => undef,
                                                  'zip' => undef,
                                                  'emailencoding' => undef,
                                                  'lastupdated' => '2004-05-06
17:46:38',
                                                  'signature' => undef,
                                                  'externalauthid' => undef,
                                                  'address1' => undef,
                                                  'workphone' => undef,
                                                  'emailaddress' => undef,
                                                  'freeformcontactinfo' => 
undef,
                                                  'city' => undef,
                                                  'gecos' => undef,
                                                  'organization' => undef,
                                                  'country' => undef,
                                                  'mobilephone' => undef,
                                                  'nickname' => undef,
                                                  'externalcontactinfoid' => 
undef,
                                                  'address2' => undef,
                                                  'created' => '2004-05-06
17:46:38',
                                                  'pgpkey' => undef,
                                                  'pagerphone' => undef,
                                                  'lastupdatedby' => '0'
                                                },
                                    'fetched' => {
                                                   'creator' => 1,
                                                   'comments' => 1,
                                                   'state' => 1,
                                                   'webencoding' => 1,
                                                   'realname' => 1,
                                                   'password' => 1,
                                                   'authsystem' => 1,
                                                   'homephone' => 1,
                                                   'id' => 1,
                                                   'timezone' => 1,
                                                   'lang' => 1,
                                                   'name' => 1,
                                                   'contactinfosystem' => 1,
                                                   'zip' => 1,
                                                   'emailencoding' => 1,
                                                   'signature' => 1,
                                                   'lastupdated' => 1,
                                                   'externalauthid' => 1,
                                                   'address1' => 1,
                                                   'workphone' => 1,
                                                   'emailaddress' => 1,
                                                   'freeformcontactinfo' => 1,
                                                   'city' => 1,
                                                   'gecos' => 1,
                                                   'organization' => 1,
                                                   'country' => 1,
                                                   'mobilephone' => 1,
                                                   'nickname' => 1,
                                                   'externalcontactinfoid' => 1,
                                                   'address2' => 1,
                                                   'created' => 1,
                                                   'pgpkey' => 1,
                                                   'lastupdatedby' => 1,
                                                   'pagerphone' => 1
                                                 }
                                  }, 'RT::CurrentUser' ),
                 'limit_clause' => '',
                 'DBIxHandle' => bless( {
                                          'dsn' => 'dbi:mysql:dbname=rt3_devel',
                                          'DisconnectHandleOnDestroy' => undef,
                                          'StatementLog' => []
                                        }, 'RT::Handle' ),
                 'restrictions' => {
                                     'main.CustomField' => [
                                                             {
                                                               'value' =>
'\'Environment\'',
                                                               'op' => '=',
                                                               'field' =>
'main.CustomField'
                                                             }
                                                           ]
                                   },
                 'primary_key' => 'id',
                 'auxillary_tables' => '',
                 'must_redo_search' => 1,
                 'itemscount' => 0,
                 'show_rows' => 0,
                 'aliases' => [],
                 'first_row' => 0
               }, 'RT::CustomFieldValues' );

I don't quite get this though.  Why won't it print out the values held in the 
CF?

Mathew
_______________________________________________
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

Community help: http://wiki.bestpractical.com
Commercial support: [EMAIL PROTECTED]


Discover RT's hidden secrets with RT Essentials from O'Reilly Media. 
Buy a copy at http://rtbook.bestpractical.com

Reply via email to