[rt-devel] Scrip Action (Long)

G. Richard Bellamy rbellamy at pteradigm.com
Tue Nov 11 00:39:47 EST 2003


Hello All,
 
Ruslan helped get me through my last question - btw, the error I was
seeing indicated that the Prepare/Commit action was returning 0 (false).

My perl (not)skills are leaving me feeling wowfully inadequate, and I
need some help.
 
Now I'm trying to do something a little more complex, namely I'm trying
to set the priority to a value indicated in the body of the email. This
a precursor to an automated email parser that will let me set the values
of the ticket via the body of the email. I need to get through the
basics before I try to tackle the more significant tasks, and figured
dealing with the priority would be a simpler way to do that.

My Scrip is designed to parse an email finding the string "Priority:XX",
where "XX" is some value, pull that value and set the priority to that
value.

===============================
Description :Set Priority
 
Condition   :On Create 
 
Action      :User Defined
 
Custom action preparation code:
my $MatchString = "iority:\s*(\w+)";
my $Ticket = $self->TicketObj;
my $Transaction = $self->TransactionObj;
my $found = 0;

$RT::Logger->info("entering 'Set Priority' Scrip for Support Queue.");
$RT::Logger->info("Message Content: " .
$Transaction->Attachments->First->Content);

$found = ($Transaction->Attachments->First->Content =~ /$MatchString/m);
if ($1) { 
   $_ = $1; 
} else { 
   $_ = $&; 
}
# be sure the match is in $_
if ($found) {
   $RT::Logger->info("matched Priority value: $_");
} else {
   $RT::Logger->info("failed to match Priority value: $_");
   $_ = "";
}
if ($_) {
   $Ticket->SetPriority($_);
} else {
   return(0);
}
return(1);
 
Custom action cleanup code:
return(1); 
 
Template    :Global template: Blank
===============================

When the incoming mail is HTML, the error log reads thus:

===============================
Nov 10 21:35:02 support RT: entering 'Set Priority' Scrip for Support
Queue. ((eval 5042):6)  
Nov 10 21:35:02 support RT: Message Content:  ((eval 5042):7)  
Nov 10 21:35:02 support RT: failed to match Priority value: correspond
((eval 5042):19)  
Nov 10 21:35:02 support RT: RT::Scrip=HASH(0xba58518): Couldn't prepare
User Defined (/opt/rt3/lib/RT/Scrip_Overlay.pm:338)  
Nov 10 21:35:02 support RT: Ticket 465 created in queue 'Support' by
rbellamy (/opt/rt3/lib/RT/Ticket_Overlay.pm:635)  
===============================

When the ticket is plain text, it reads like so:

===============================
Nov 10 21:35:38 support RT: entering 'Set Priority' Scrip for Support
Queue. ((eval 5069):6)  
Nov 10 21:35:38 support RT: Message Content: Priority:50     G. Richard
Bellamy  Enterprise Solution Architect  Pteradigm - Evolutionary
mailto:rbellamy at pteradigm.com  V:707-869-3665     ((eval 5069):7)  
Nov 10 21:35:38 support RT: failed to match Priority value: correspond
((eval 5069):19)  
Nov 10 21:35:38 support RT: RT::Scrip=HASH(0xb91ac2c): Couldn't prepare
User Defined (/opt/rt3/lib/RT/Scrip_Overlay.pm:338)  
Nov 10 21:35:38 support RT: Ticket 466 created in queue 'Support' by
rbellamy (/opt/rt3/lib/RT/Ticket_Overlay.pm:635)  
===============================

Any help would be greatly appreciated.

-rb




More information about the Rt-devel mailing list