adric.net

RTSampleAutofilingScrip
Login
### example_scrip for RT automation

# if applicable run scrip actions: ##if ticket's subject line matches 'keywordstring' ## and ticket's sender matches 'root@hostname' ##then ## assign ticket to Application Queue

## assign ticket to Inspector value of CF Application ## comment ticket "autofiled and autoresolved by scrip" with datestamp ## set ticket status to resolved

### from: http://wiki.bestpractical.com/view/WriteCustomCondition ### and: http://wiki.bestpractical.com/view/ApproximateSeparateQueues ### and: Request Tracker Boot Camp Presentation.pdf

### Condition: On Create

### Action: User Defined

### Template: Global template: Blank ## maybe autofiling_template

### Custom Condition:

##if ticket's subject line matches 'Low risk emergency maintenance notice at' ## and ticket's sender matches 'root@inspector'

### subject match on keyword and sender for only one transaction if ($self->TransactionObj->Subject =~ /keyword/i && $self->TransactionObj->CreatorObj->EmailAddress =~ /root\@hostname/i && $self->TicketObj->Transactions->Count == 1) { ## not certain? 1; } else { 0; }

### Custom action preparation code: return 1;

### Custom Action Cleanup Code:

# get ticket object my $ticket = $self->TicketObj; my $scriptname = "RT Autofile Scrip v0.0"; my $newqueue = "2"; ## 2 for Application

## assign ticket to Application Queue unless we can't $ticket->SetQueue($newqueue); my ($status, $msg) = $ticket->SetQueue($newqueue); unless ($status) { $RT::Logger->error($scriptname.": unable to set #".$ticket->id." to queue: "$newqueue."with". $msg); return undef; } $RT::Logger->info($scriptname.": Auto assign ticket #". $ticket->id ." to queue #".$newqueue );

## assign ticket to Inspector value of CF Application my $CF_name = 'Application'; my $CF = RT::CustomField->new( $RT::SystemUser ); $CF->LoadByNameAndQueue( Name => $CF_name, Queue => $ticket->Queue ); my $CF_value = 'Inspector';

$self->TicketObj->AddCustomFieldValue( Field => $CF, Value => $CF_value ); unless ( $CF->id ) { $RT::Logger->error($scriptname." : assign failed. RT#". $ticket->id." ".$CF->id." ".$CF_value ); return undef; ## bad. } $RT::Logger->info($scriptname." : Auto assign RT#". $ticket->id ." CF ".$CF->id . " to value ". $cf_value );

## comment ticket "autofiled and autoresolved by scrip" with datestamp ### This is performed by template and logged as we go.

## set ticket status to resolved my ($status, $msg) = $ticket->SetStatus('resolved'); unless ($status) { $RT::Logger->error($scriptname.": unable to resolve #".$ticket->id); } $RT::Logger->info($scriptname." : Auto resolve RT#". $ticket->id);

return 1;

###