Setting custom field value via template

Hi All,

I’m getting an error that is beyond my capability to figure out. I have an
’Autoreply’ template in a queue that is supposed to do a couple of things
when a new ticket is created in that queue via e-mail. The first thing it
does is to grep an IP address and incident number from the mail text and
subject. This works just fine. The next thing it is supposed to do is
fill in values for 2 custom fields (‘IP’ and ‘Incident number’) in the
newly-created ticket. This is where I’m getting the error that I can’t
figure out. I found some code in the wiki that claims to set a custom
field value, so I copied it into the template and turned it into a function
so I could call it for each custom field that I want to set.

The error I’m getting is:
"[Tue Mar 20 16:44:59 2007] [error]: Template parsing error: Can’t call
method “TicketObj” on an undefined value at template line 30."

I’m pretty sure the line that is being flagged is the 2nd one in my
function (“my $QueueObj = …”). Is it possible that the ticket isn’t
created until after the Autoreply template has done its thing?

Here is the code where I call the function, followed by the function
itself. I’d appreciate it if someone could tell me what the problem is.

if (defined $IP) {
set_custom(‘IP’, $IP);
if (defined $incident) {
set_custom(‘Incident number’, $incident);

sub set_custom {
my ($CFName, $CFValue) = @_;
my $QueueObj = $self->TicketObj->QueueObj;
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->warning(“custom field ‘$CFName’ isn’t global or defined
for queue '”. $QueueObj->Name ."’");
return undef;
unless( $self->TicketObj->FirstCustomFieldValue( $CFObj->id ) ) {
my( $st, $msg ) = $self->TicketObj->AddCustomFieldValue(
Field => $CFObj->id,
Value => $CFValue,
RecordTransaction => 1 );
unless( $st ) {
$RT::Logger->warning( “Couldn’t set $CFValue as value for CF
$CFName:”. $msg);


Gene LeDuc, GSEC
Security Analyst
San Diego State University