[rt-users] Pulling CustomFieldValues

Mathew Snyder theillien at yahoo.com
Thu Nov 23 03:36:28 EST 2006


Stephen Turner wrote:
>> -----Original Message-----
>> From: rt-users-bounces at lists.bestpractical.com 
>> [mailto:rt-users-bounces at lists.bestpractical.com] On Behalf 
>> Of Mathew Snyder
>> Sent: Wednesday, November 22, 2006 3:35 AM
>> To: rt-users at lists.bestpractical.com
>> Subject: [rt-users] Pulling CustomFieldValues
>>
>> I'm trying to pull together a script which will print out all 
>> the values from a
>> particular CF.  It will work in conjunction with a bit of 
>> code already provided
>> to me by Roy El-Hames.
>>
>> I think I've figured out that I need to use 
>> RT::CustomFieldValues in order to
>> make use of the LimitToCustomField subroutine.  What I can't 
>> figure out is how
>> to pass the name of the CF to the subroutine.  Being a perl 
>> novice this eludes me.
>>
>> This is what I have so far:
>>
>> #!/usr/bin/perl
>> use lib "/usr/local/rt-3.6.1/lib";
>> use RT;
>> use RT::Users ; ## you may not need this but what the he
>> use RT::CustomFieldValues;
>> use RT::Interface::CLI qw(CleanEnv);
>> use warnings;
>>
>> CleanEnv();   ##Cleaning the env
>> RT::LoadConfig();   ## Loading RT config
>> RT::Init();    ## Initialise RT
>>
>> my $users = new RT::Users(RT::SystemUser);
>> $users->LimitToPrivileged;
>> my $CustomField = new RT::CustomFieldValues(Profiles);
>> $CustomField->LimitToCustomField;
>>
>> while ( $user = $users->Next) {
>>    next if $user->Name eq "root";
>>    print $user->Name . "\n";
>> }
>> exit;
>>
>> Can someone help me out and point me in the right direction?
>>
>> Thanks,
>> Mathew
>>
> 
> Mathew,
> 
> You can get at the values by using the  LimitToCustomField method on a
> CustomFieldValues object, but you need to supply the custom field's Id as an
> argument: 
> 
> $CustomField->LimitToCustomField (VALUE => $cf_id);
> 
> assuming you've got the CF id in $cf_id.
> 
> So first you'd have to load up a CustomField object and get the Id from
> there. Incidentally, it might be misleading to call the CustomFieldValues
> object $CustomField.
> 
> Another approach is to load the CustomField object and use the object's
> Values() method. This returns a CustomFieldValues object which you can then
> iterate through to see the CustomFieldValue objects.
> 
> Steve
> 
> 

This is beginning to make my head hurt.  I assume by loading up a CustomField
object you mean use the Load subroutine in CustomField_Overlay.pm.  There is a
subroutine called Load that checks if an ID or Name is provided.  So would it be:
my $cf_id = RT::CustomField->Load(Name => "Profiles");

This is confusing.

Mathew




More information about the rt-users mailing list