Adding a CustomField to a ticket?

Hi,

I’ve been experimenting this morning with a scrip to extract information
from some fields in a ticket, and fill in some additional information in
a customfield, based on those fields. The scrip works, but only if the
ticket was created in the appropriate queue, and not moved there.

Apparently, if it was moved into the queue, it doesn’t gain the CFs for
that queue. Unfortunately, the way we have RT setup, almost all mails go
into General before being re-filed by us (we don’t trust our customers
to categorise their problem, basically). Is there a way to add a CF to a
ticket from within a scrip, or alternatively, is there something else I
need to do to inherit a CF when the ticket moves?

My script action is currently:

my $tick = $self->TicketObj;
my $requestor = $tick->RequestorAddresses;
my $cf = $tick->QueueObj->CustomField(‘OutageSource’);

if($requestor ne “”)
{
$tick->DeleteWatcher(Type=>‘Requestor’,Email=>$requestor);
$tick->AddCustomFieldValue(Field=>$cf,Value=>$requestor);
$RT::Logger->warning(“Removing requestor, adding CF value”);
}
return 1;

I have a couple of similar but more involved scrips I was planning to
write, but obviously I’d like to get past this bit first!

Thanks in advance,

Howard

What is the scrip condition?On Tue, Oct 18, 2005 at 10:51:04AM +0100, Howard Jones wrote:

Hi,

I’ve been experimenting this morning with a scrip to extract information
from some fields in a ticket, and fill in some additional information in
a customfield, based on those fields. The scrip works, but only if the
ticket was created in the appropriate queue, and not moved there.

Apparently, if it was moved into the queue, it doesn’t gain the CFs for
that queue. Unfortunately, the way we have RT setup, almost all mails go
into General before being re-filed by us (we don’t trust our customers
to categorise their problem, basically). Is there a way to add a CF to a
ticket from within a scrip, or alternatively, is there something else I
need to do to inherit a CF when the ticket moves?

My script action is currently:

my $tick = $self->TicketObj;
my $requestor = $tick->RequestorAddresses;
my $cf = $tick->QueueObj->CustomField(‘OutageSource’);

if($requestor ne “”)
{
$tick->DeleteWatcher(Type=>‘Requestor’,Email=>$requestor);
$tick->AddCustomFieldValue(Field=>$cf,Value=>$requestor);
$RT::Logger->warning(“Removing requestor, adding CF value”);
}
return 1;

I have a couple of similar but more involved scrips I was planning to
write, but obviously I’d like to get past this bit first!

Thanks in advance,

Howard


http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

Be sure to check out the RT Wiki at http://wiki.bestpractical.com

Buy your copy of our new book, RT Essentials, today!

Download a free sample chapter from http://rtbook.bestpractical.com

Here is a scrip we use to move tickets into a queue when they are created
based upon subject line. RT doesn’t show the ticket being moved, so I think
this scrip is actually causing the ticket to be created in the new queue.
See if this might work for you.

Description: AutoChange Queue
Condition: On Create
Custom condition:
Action: User Defined
Custom Action Preparation code: return 1;
Custom Action Cleanup code: # get out unless subject is like ursuant
return 1 unless $self->TicketObj->Subject =~ /ursuant/;

ok, try to change queue

$RT::Logger->info(“Auto transfer ticket #”. $self->TicketObj->id ." to the
Pursuant Queue" );
my ($status, $msg) = $self->TicketObj->SetQueue( ‘8’ );
unless( $status ) {
$RT::Logger->warning( “Impossible to change Queue” );
return undef;
}
return 1;
Stage: TransactionCreate
Template: Global template: Blank

Thanks,
Tim
972-980-4991From: Todd Chapman [mailto:todd@chaka.net]
Sent: Tuesday, October 18, 2005 7:03 AM
To: Howard Jones
Cc: rt-users@lists.bestpractical.com
Subject: Re: [rt-users] Adding a CustomField to a ticket?

What is the scrip condition?

Hi,

I’ve been experimenting this morning with a scrip to extract
information from some fields in a ticket, and fill in some additional
information in a customfield, based on those fields. The scrip works,
but only if the ticket was created in the appropriate queue, and not moved
there.

Apparently, if it was moved into the queue, it doesn’t gain the CFs
for that queue. Unfortunately, the way we have RT setup, almost all
mails go into General before being re-filed by us (we don’t trust our
customers to categorise their problem, basically). Is there a way to
add a CF to a ticket from within a scrip, or alternatively, is there
something else I need to do to inherit a CF when the ticket moves?

My script action is currently:

my $tick = $self->TicketObj;
my $requestor = $tick->RequestorAddresses;
my $cf = $tick->QueueObj->CustomField(‘OutageSource’);

if($requestor ne “”)
{
$tick->DeleteWatcher(Type=>‘Requestor’,Email=>$requestor);
$tick->AddCustomFieldValue(Field=>$cf,Value=>$requestor);
$RT::Logger->warning(“Removing requestor, adding CF value”);
}
return 1;

I have a couple of similar but more involved scrips I was planning to
write, but obviously I’d like to get past this bit first!

Thanks in advance,

Howard


http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

Be sure to check out the RT Wiki at http://wiki.bestpractical.com

Buy your copy of our new book, RT Essentials, today!

Download a free sample chapter from http://rtbook.bestpractical.com
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

Be sure to check out the RT Wiki at http://wiki.bestpractical.com

Buy your copy of our new book, RT Essentials, today!

Download a free sample chapter from http://rtbook.bestpractical.com

Todd Chapman wrote:

What is the scrip condition?

It’s this, but I don’t think it’s relevant…
my $ticket = $self->TicketObj;
if ( $ticket->RequestorAddresses ne ‘’) {
return(1);
}
return(undef);

The part that isn’t working is the SetCustomField… if a ticket is
created in General, and then moved to this ‘outages’ queue then it
hasn’t got the CF that is defined for the outages queue.

Best Regards,

Howard

Howard Jones wrote:

my $cf = $tick->QueueObj->CustomField(‘OutageSource’);

I think this is where you’re going south. Custom Fields are independent
objects, not actually part of the Queue object.

I got this out of the Wiki (I’ve replaced some of the variable names to
match your code):

my $QueueObj = $self->TicketObj->QueueObj;
my $cf = RT::CustomField->new( $QueueObj->CurrentUser );

$cf->LoadByNameAndQueue( Name => ‘OutageSource’, Queue => 0 );

for global CFs: Queue => 0

for queue CFs: Queue => QueueObj->id

my( $st, $msg ) = $self->TicketObj->AddCustomFieldValue(
Field => $cf->id,
Value => $requestor,
RecordTransaction => 1 );

For computer help, call xHELP (x4357 or 713-348-4357)
On the web: http://helpdesk.rice.edu/
Rick Russell
Helpdesk Supervisor, Client Services
IT/Academic & Research Computing
Rice University
Voice: 713.348.5267 Fax: 713.348.6099
OpenPGP/GnuPG Public Key at ldap://certificate.rice.edu
761D 1C20 6428 580F BD98 F5E5 5C8C 56CA C7CB B669

signature.asc (256 Bytes)

Rick Russell wrote:

Howard Jones wrote:

my $cf = $tick->QueueObj->CustomField(‘OutageSource’);

I think this is where you’re going south. Custom Fields are independent
objects, not actually part of the Queue object.

I got this out of the Wiki (I’ve replaced some of the variable names to
match your code):

my $QueueObj = $self->TicketObj->QueueObj;
my $cf = RT::CustomField->new( $QueueObj->CurrentUser );

$cf->LoadByNameAndQueue( Name => ‘OutageSource’, Queue => 0 );

for global CFs: Queue => 0

for queue CFs: Queue => QueueObj->id

my( $st, $msg ) = $self->TicketObj->AddCustomFieldValue(
Field => $cf->id,
Value => $requestor,
RecordTransaction => 1 );

Aha! That did the trick. Thanks Rick.