[rt-users] Pulling CustomFieldValues

Stephen Turner sturner at MIT.EDU
Wed Nov 29 09:14:30 EST 2006


  

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




More information about the rt-users mailing list