[rt-users] Help request: Custom scrip action

Andy Harrison aharrison at gmail.com
Tue Feb 22 13:53:54 EST 2005


On Mon, 21 Feb 2005 11:31:35 -0600, Tim Wilson
<tim_wilson at hopkins.k12.mn.us> wrote:
> Hi everyone,
> 
> My organization is planning to use RT to track equipment orders. Once the
> equipment is received at the central office, it's distributed out to a bunch
> of other site. We've created a queue for this purpose called "Tech-orders".
> 
> I'm using the excellent ExtractCustomFieldValues.pm package to populate a
> custom field with the abbreviated names of the buildings where the equipment
> will eventually be delivered. That works fine. Now I'm adding another custom
> Action that is supposed to scan through the contents of that custom field
> and add certain users as Ccs for the ticket. (Each building has a different
> person(s) in charge of deploying the equipment once it's installed.) This is
> to notify those persons to be on the lookout for the equipment.
> 
> I'm a perl newbie, but this is the code I've come up with. I've included the
> relevant portion of the RT log that shows the scrip failing. I would
> appreciate any and all suggestions very much.
> 
> -Tim
> 
> My code:
> 
> package RT::Action::AddCcFromBuildingList;
> require RT::Action::Generic;
> 
> use strict;
> use vars qw/@ISA/;
> @ISA=qw(RT::Action::Generic);
> 
> sub Describe  {
>   my $self = shift;
>   return (ref $self );
> }
> 
> sub Prepare {
>   return (1);
> }
> 
> sub Commit {
>   my %building_watchers = (
>     "ESC" => ["user1\@example.com",
>               "user2\@example.com"],
>     "HHS" => ["user3\@example.com"]
>   );
>   my $cclist = $self->TicketObj->Cc;
>   my $CustomFields = $Ticket->QueueObj->CustomFields();
>   my $BuildingList = $Ticket->FirstCustomFieldValue('Building List');
> 
>   while (my $Building = $BuildingList->Next) {
>     foreach $email (@{building_watchers{$Building}}) {
>       my $user = RT::User->new($RT::SystemUser);
>       $user->LoadByEmail($email);
>       $cclist->AddMember($user->Id);
>     }
>   }
>   return(1);
> }
> 
> 1;
> 
> Logging output:
> 
> [Mon Feb 21 16:39:37 2005] [error]: Scrip Prepare 28 died. - Require of
> RT::Action::AddCcFromBuildingList failed.
> Global symbol "$self" requires explicit package name at
> /usr/share/request-tracker3.2/lib/RT/Action/AddCcFromBuildingList.pm line
> 23.
> Global symbol "$Ticket" requires explicit package name at
> /usr/share/request-tracker3.2/lib/RT/Action/AddCcFromBuildingList.pm line
> 24.
> Global symbol "$Ticket" requires explicit package name at
> /usr/share/request-tracker3.2/lib/RT/Action/AddCcFromBuildingList.pm line
> 25.
> Global symbol "$email" requires explicit package name at
> /usr/share/request-tracker3.2/lib/RT/Action/AddCcFromBuildingList.pm line
> 28.
> Global symbol "$email" requires explicit package name at
> /usr/share/request-tracker3.2/lib/RT/Action/AddCcFromBuildingList.pm line
> 30.
> Compilation failed in require at (eval 318) line 3.

You're confusing scrips with perl modules.

You can do it right inside a scrip.  Here is an example from one of mine. 

Description: AddWatcherFoo
Condition: User defined
Custom Condition: 
return undef unless ($self->TransactionObj->Type eq "Create");
return undef unless ($self->TicketObj->FirstCustomFieldValue('MyField') =~ 
 /SomeValue/i);

Action: User defined
Custom action preparation code:

my ($status, $msg) = $self->TicketObj->AddWatcher(Type => 'Cc', Email
=> "foo\@example.com" );
return 1;

Custom action cleanup code:
return 1;

Stage: TransactionCreate
Template: Global template: Blank

-- 
Andy Harrison



More information about the rt-users mailing list