> -----Original Message-----
> From: Mathew Snyder [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, November 29, 2006 4:29 AM
> To: [EMAIL PROTECTED]
> Cc: [email protected]
> 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
_______________________________________________
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