[rt-users] Pulling CustomFieldValues

Stephen Turner sturner at MIT.EDU
Wed Nov 22 09:44:48 EST 2006


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




More information about the rt-users mailing list