[rt-users] Pulling CustomFieldValues
Mathew Snyder
theillien at yahoo.com
Thu Dec 7 02:53:58 EST 2006
Stephen Turner wrote:
>
>
>> -----Original Message-----
>> From: Mathew Snyder [mailto:theillien at yahoo.com]
>> Sent: Wednesday, November 29, 2006 4:29 AM
>> To: sturner at MIT.EDU
>> Cc: rt-users at lists.bestpractical.com
>> Subject: Re: [rt-users] Pulling CustomFieldValues
>>
>> Steve,
>>
>> This is the code I now have:
>>
>> my $cf = RT::CustomField->new(RT::SystemUser);
>> $cf->Values($cf_name);
>> foreach my $cf_key (${cf}){
>> print $$cf_key{"KEY"} . "\n";
>> };
>>
>> 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?
>>
>> Mathew
>>
>
> Hi Mathew,
>
> You're getting close! The Values method actually returns a CustomFieldValues
> object, even though a print will show a hash. This object represents a
> collection of CustomFieldValue objects and you can iterate through the value
> objects using the RT collections API (see RTx::SearchBuilder):
>
> My $cfvalues = $cf->Values($cf_name);
> while (my $cfval = $cfvalues->Next() ){
> print $cfval->Name . "\n";
> };
>
> You can see this in action on the custom field 'modify' screen - (
> /Admin/CustomFields/Modify.html ). This calls
> /Admin/Elements/EditCustomFieldValues which displays a list of the existing
> values for the CF.
>
> Steve
>
>
I guess it's time to revisit this after taking a break for a bit.
The code I now have, based on the above is thus:
!/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);
my $cfvalues = $cf->Values($cf_name);
while (my $cfval = $cfvalues->Next() ){
print $cfval->Name . "\n";
};
exit;
This will run and place me right back at the prompt without any output. I guess
I just don't understand how to get the values of the custom field.
Mathew
More information about the rt-users
mailing list