[rt-users] getting the values of custom fields

Joop JoopvandeWege at mococo.nl
Wed Feb 14 03:28:05 EST 2007


anthony wrote:
> I'm doing this via script action.
> FirstCustom.. is in Record which is not part of the $self.
> 
> I get TicketObj, TransactionObj ( which does not seems to work )
> 
> I'm tried to use CustomFieldValues but I get stuck after that.
> 
> Searches through the archive seem to say NO ONE has done this successfully.
This is part of our script which ties timeworked to an asset which hold 
how many hours a client has left on his contract.
use Data::Dumper;

# start to define a couple of useful objects.
my $TicketObj = $self->TicketObj;
my $QueueObj  = $self->TicketObj->QueueObj;
my $TransObj  = $self->TransactionObj;
my $TemplObj  = $self->TemplateObj;
# $RT::Logger->debug( Dumper($TemplObj) );
my $qname     = $self->TicketObj->QueueObj->Name;
my $cfname    = 'Strippenkaart';
my $timetaken;
my $abstimetaken_new;
my $abstimetaken_old;
my $assettype;

# $RT::Logger->debug("$qname");
# $RT::Logger->debug("$timetaken");
my $ttype  = $TransObj->Type;
my $tfield = $TransObj->Field;
# $RT::Logger->debug($ttype);
# $RT::Logger->debug($tfield);

# make a new CFObj and fill it
my $CFObj = RT::CustomField->new( $QueueObj->CurrentUser );
$CFObj->LoadByNameAndQueue( Name => $cfname, Queue => $QueueObj->id );
unless ( $CFObj->id ) {
     $CFObj->LoadByNameAndQueue( Name => $cfname, Queue => 0 );
     unless ( $CFObj->id ) {
         $RT::Logger->debug(
                     "custom field '$cfname' isn't global or defined for 
queue '"
                       . $QueueObj->Name
                       . "'" );
         return undef;
     }
}

# get the first CFValue
my $cfvalue = $self->TicketObj->FirstCustomFieldValue( $CFObj->id );
$RT::Logger->debug("$cfvalue");

# then create an empty AssetObj with the current user
my $AssetObj = RTx::AssetTracker::Asset->new( $QueueObj->CurrentUser );

# get its values given the convention  AssetName=QueueName+CFValue
# check if status == production
# further Name is unique in the DB, is possible to change via 
AT_SiteConfig.pm
# still check if  AssetType==Strippenkaart
$AssetObj->Load($qname.$cfvalue);
$assettype=$AssetObj->TypeObj->Name;
if ( $assettype ne 'Strippenkaart' ) {
     $RT::Logger->debug("No Asset of type Strippenkaart");
     return undef;
}

my $desc   = $AssetObj->Description;
my $status = $AssetObj->Status;
if ( $status ne 'production' ) { return undef; }

# $RT::Logger->debug("$desc");

# get the CustomFields  (cnt>0)
my $AssetCFObj = $AssetObj->CustomFields();
my $cfcount = $AssetCFObj->Count;
if ( $cfcount == 0 ) { return undef; }

# process the CF's


Does this make sense?

Joop





More information about the rt-users mailing list