[rt-devel] Scrip Action (Long)

Ruslan U. Zakirov cubic at acronis.ru
Wed Nov 12 02:47:26 EST 2003


G. Richard Bellamy wrote:
> 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+)";
\w == [a-zA-Z](alphabetical chars no digits so you need \d)
> 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);

My variant:

my $Ticket = $self->TicketObj;
my $Transaction = $self->TransactionObj;
my $p;

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

if(($p) = ($Transaction->Attachments->First->Content =~ 
/Priority:\s*(\d+)/im)) {
    $RT::Logger->info("matched Priority value: $p");
    $Ticket->SetPriority($p);
} else {
    $RT::Logger->info("failed to match Priority value: $_");
    return(0);
}
return(1);




More information about the Rt-devel mailing list