SetCustomFieldViaMail: Difference between revisions

From Request Tracker Wiki
Jump to navigation Jump to search
m (2 revisions imported)
 
Line 41: Line 41:
== EXAMPLE 2: CF Value based on requestor's email address (returns $1 @ $2) ==
== EXAMPLE 2: CF Value based on requestor's email address (returns $1 @ $2) ==


Condition:  OnCreate
    Condition:  OnCreate
Action:  User Defined
    Action:  User Defined
Template: Global template: Transaction
    Template: Global template: Transaction
Stage: TransactionCreate
    Stage: TransactionCreate


CUSTOM CONDITION:
CUSTOM CONDITION:
Line 51: Line 50:
PREPARATION CODE:
PREPARATION CODE:


return 1;
    return 1;


CLEANUP CODE:
CLEANUP CODE:


my $ticketRequestor = lc($self->TicketObj->RequestorAddresses);
    my $ticketRequestor = lc($self->TicketObj->RequestorAddresses);
$ticketRequestor =~ /(^.+)@([^\.].*\.[a-z]{2,}$)/;
    $ticketRequestor =~ /(^.+)@([^\.].*\.[a-z]{2,}$)/;
   
if ( $1 =~ /^username$/m ) {
    if ( $1 =~ /^username$/m ) {
$self->TicketObj->AddCustomFieldValue( Field => 'Region', Value => 'ONE' );
      $self->TicketObj->AddCustomFieldValue( Field => 'Region', Value => 'ONE' );
}
    }
   
if ( $2 =~ /^yourdomain.net$/m ) {
    if ( $2 =~ /^yourdomain.net$/m ) {
$self->TicketObj->AddCustomFieldValue( Field => 'Region', Value => 'TWO' );
      $self->TicketObj->AddCustomFieldValue( Field => 'Region', Value => 'TWO' );
}
    }
   
$self->TicketObj->SetPriority( 1 );
    $self->TicketObj->SetPriority( 1 );
   
return 1;
    return 1;


== EXAMPLE 3: CF & Title change based on requestor's email address (returns $1 @ $2) ==
== EXAMPLE 3: CF & Title change based on requestor's email address (returns $1 @ $2) ==

Revision as of 22:34, 20 February 2019

RT 3.8

The following example Scrips will help set ticket's CF values, change title or parameters, and notify specific groups based on email properties as detected by RT; Examples partially based on older WiKi entries and adapted where needed. CF names and values are purely fictional examples, please don't copy and paste without proper understanding of setup and requirements. Requestors will need appropriate permissions to create/modify CF values for this to work.

Posted & Tested on 3.8.7 by webdelic@gmail.com

EXAMPLE 1: CF Value based on destination email address

Condition:  OnCreate
Action:  User Defined
Template: Global template: Transaction
Stage: TransactionCreate

CUSTOM CONDITION:

PREPARATION CODE:

return 1;

CLEANUP CODE:

my $to = $self->TransactionObj->Attachments->First->GetHeader('To');

if ($to =~/^partial\@.*\.?yourdomain\.net/) {
$self->TicketObj->AddCustomFieldValue( Field => 'Region', Value => 'ONE' );
}

if ($to =~/fixed\@.*\.?yourdomain\.net/) {
$self->TicketObj->AddCustomFieldValue( Field => 'Region', Value => 'TWO' );
}

$self->TicketObj->SetPriority( 1 );

return 1;



EXAMPLE 2: CF Value based on requestor's email address (returns $1 @ $2)

   Condition:  OnCreate
   Action:  User Defined
   Template: Global template: Transaction
   Stage: TransactionCreate

CUSTOM CONDITION:

PREPARATION CODE:

   return 1;

CLEANUP CODE:

   my $ticketRequestor = lc($self->TicketObj->RequestorAddresses);
   $ticketRequestor =~ /(^.+)@([^\.].*\.[a-z]{2,}$)/;
   
   if ( $1 =~ /^username$/m ) {
     $self->TicketObj->AddCustomFieldValue( Field => 'Region', Value => 'ONE' );
   }
   
   if ( $2 =~ /^yourdomain.net$/m ) {
     $self->TicketObj->AddCustomFieldValue( Field => 'Region', Value => 'TWO' );
   }
   
   $self->TicketObj->SetPriority( 1 );
   
   return 1;

EXAMPLE 3: CF & Title change based on requestor's email address (returns $1 @ $2)

Condition:  OnCreate
Action:  User Defined
Template: Global template: Transaction
Stage: TransactionCreate

CUSTOM CONDITION:

PREPARATION CODE:

return 1;

CLEANUP CODE:

my $ticketRequestor = lc($self->TicketObj->RequestorAddresses);
$ticketRequestor =~ /(^.+)@([^\.].*\.[a-z]{2,}$)/;

if ( $2 =~ /^gmail.com$/m ) {
$self->TicketObj->AddCustomFieldValue( Field => 'Some CF', Value => 'SOME VALUE' );
$self->TicketObj->AddCustomFieldValue( Field => 'Region', Value => 'ONE' );
$self->TicketObj->SetSubject ('TAG: '.$self->TicketObj->Subject);
}



EXAMPLE 4: Notify Groups based on req/destination email or CF Values

Pre-Requirements:

* You will have to create specific sub-groups and add members to be notified
 * You will need "rt-notify-group-admin" to create scrip Actions to notify the above sub-groups
 
 
 
 Condition:  User Defined
 Action:  Notify YOURGROUP
 Template: Global template: Transaction
 Stage: TransactionCreate
 
 

CUSTOM CONDITION:

my $to = $self->TransactionObj->Attachments->First->GetHeader('To');
my $ticketRequestor = lc($self->TicketObj->RequestorAddresses);
$ticketRequestor =~ /(^.+)@([^\.].*\.[a-z]{2,}$)/;

if ($to =~/^nms\@.*\.?yourdomain\.net/) {
$self->TicketObj->AddCustomFieldValue( Field => 'Type', Value => 'NAGIOS' );
return 1; } else { return 0;}

if ( $1 =~ /^nagios$/m ) {
$self->TicketObj->AddCustomFieldValue( Field => 'Type', Value => 'NAGIOS' );
return 1; } else { return 0;}


PREPARATION CODE:

return 1;

CLEANUP CODE:

return 1;

RT 3.6 and older

See AutomaticCustomFieldValue