AutoreplyOrCorrespondence: Difference between revisions

From Request Tracker Wiki
Jump to navigation Jump to search
(Created page with "When creating a ticket on someone's behalf this template code will choose to use the Autoreply or Correspondence templates. If the ticket creator is not a requestor or there is m...")
 
No edit summary
Line 1: Line 1:
When creating a ticket on someone's behalf this template code will choose to use the Autoreply or Correspondence templates. If the ticket creator is not a requestor or there is more than one requestor the Correspondence template is used, otherwise an Autoreply template is used.
This template code checks to see if the creator is the same as one of the requestors on ticket creation. If so it loads and processes the Autoreply template searching first in the current queue and if there isn't one there resorting to theglobal version.
 
If the requestor is not the creator then it processes the Correspondence template instead doing the same search as above.
 
The effect of using this template is that if a ticket is created on behalf of a customer they receive the message you create (on ticket creation) as if it is a reply rather than the default cryptic auto-reply.
 
It assumes there are at least global templates 'Autoreply' and 'Correspondence'.






  <nowiki>
  <nowiki>
  {
  {
    use RT::Template;
    use RT::Template;
    my $creator_name = $Ticket->CreatorObj->Name;
    my $creator_name = $Ticket->CreatorObj->Name;
    my $requestors = $Ticket->Requestors->UserMembersObj;
    my $requestors = $Ticket->Requestors->UserMembersObj;
    my ( $c_requestor, $r_count ) = ( 0, 0 );
    my ( $c_requestor, $r_count ) = ( 0, 0 );
    while ( my $r = $requestors->Next() ) {
    while ( my $r = $requestors->Next() ) {
        if ( $r->Name eq $creator_name ) {
        if ( $r->Name eq $creator_name ) {
            $c_requestor++;
            $c_requestor++;
        }
        }
        else {
        else {
            $r_count++;
            $r_count++;
        }
        }
    }
    }
    my $template = new RT::Template($RT::SystemUser);
    my $template = new RT::Template($RT::SystemUser);
    my $template_name;
    my $template_name;
   
   
    #if the creator is not a requestor or  
    #if the creator is not a requestor or  
    #there is more than one requestor ( who's not the creator )
    #there is more than one requestor ( who's not the creator )
    #use the Correspondence template
    #use the Correspondence template
    if ( ! $c_requestor || $r_count ) {
    if ( ! $c_requestor || $r_count ) {
        $template_name = 'Correspondence';
        $template_name = 'Correspondence';
    }
    }
    else {
    else {
        #otherwise use the Autoreply template
        #otherwise use the Autoreply template
        $template_name = 'Autoreply';
        $template_name = 'Autoreply';
    }
    }
 
    #Load the Queue Template
    #Load the Queue Template
    $template->LoadQueueTemplate(  
    $template->LoadQueueTemplate(  
        Queue => $Ticket->Queue,  
        Queue => $Ticket->Queue,  
        Name => $template_name,
        Name => $template_name,
    );
    );
    #if there's no Queue Template attempt to find a Global one.
    #if there's no Queue Template attempt to find a Global one.
    unless ( $template->id ) {
    unless ( $template->id ) {
        $template->LoadGlobalTemplate( $template_name );
        $template->LoadGlobalTemplate( $template_name );
        unless ( $template->id ) {  
        unless ( $template->id ) {  
            $RT::Logger->error("Could not load template : $template_name")
            $RT::Logger->error("Could not load template : $template_name")
        }
        }
    }
    }
    #Process embedded fields & expressions of true templates;
    #Process embedded fields & expressions of true templates;
    #note that we can only meaningfully use the body
    #note that we can only meaningfully use the body
    my($ret, $msg) = $template->Parse(
    my($ret, $msg) = $template->Parse(
                        TicketObj => $Ticket,  
                          TicketObj => $Ticket,  
                        TransactionObj => $Transaction,
                          TransactionObj => $Transaction,
                    );
                      );
    $ret ? $template->MIMEObj->stringify : $msg;
    $ret ? $template->MIMEObj->stringify : $msg;
  }
  }
</nowiki>
  </nowiki>

Revision as of 02:14, 23 May 2011

This template code checks to see if the creator is the same as one of the requestors on ticket creation. If so it loads and processes the Autoreply template searching first in the current queue and if there isn't one there resorting to theglobal version.

If the requestor is not the creator then it processes the Correspondence template instead doing the same search as above.

The effect of using this template is that if a ticket is created on behalf of a customer they receive the message you create (on ticket creation) as if it is a reply rather than the default cryptic auto-reply.

It assumes there are at least global templates 'Autoreply' and 'Correspondence'.


   {
     use RT::Template;
     my $creator_name = $Ticket->CreatorObj->Name;
     my $requestors = $Ticket->Requestors->UserMembersObj;
     my ( $c_requestor, $r_count ) = ( 0, 0 );
     while ( my $r = $requestors->Next() ) {
         if ( $r->Name eq $creator_name ) {
             $c_requestor++;
         }
         else {
             $r_count++;
         }
     }
     my $template = new RT::Template($RT::SystemUser);
     my $template_name;
     
     #if the creator is not a requestor or 
     #there is more than one requestor ( who's not the creator )
     #use the Correspondence template
     if ( ! $c_requestor || $r_count ) {
         $template_name = 'Correspondence';
     }
     else {
         #otherwise use the Autoreply template
         $template_name = 'Autoreply';
     }
 
     #Load the Queue Template
     $template->LoadQueueTemplate( 
         Queue => $Ticket->Queue, 
         Name => $template_name,
     );
     #if there's no Queue Template attempt to find a Global one.
     unless ( $template->id ) {
         $template->LoadGlobalTemplate( $template_name );
         unless ( $template->id ) { 
             $RT::Logger->error("Could not load template : $template_name")
         }
     }
     #Process embedded fields & expressions of true templates;
     #note that we can only meaningfully use the body
     my($ret, $msg) = $template->Parse(
                          TicketObj => $Ticket, 
                          TransactionObj => $Transaction,
                      );
     $ret ? $template->MIMEObj->stringify : $msg;
   }