AutoreplyOrCorrespondence

From Request Tracker Wiki
Revision as of 03:05, 23 May 2011 by 203.214.67.82 (talk) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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.


  {
    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;
  }