>
> On 3 October 2013 04:27, Ruslan Zakirov <[email protected]> wrote:
>
>> Hi,
>>
>> You can do this by inserting custom TemplateObj method into
>> RT/Action/SendMail.pm
>>
>> It should be like this:
>> 1) behave like original method, so copy it from lib/RT/Action.pm
>> 2) change template on call when Ticket and Txn are available
>> 3) mark that change was done
>>
>> For example:
>>
>> sub TemplateObj {
>>     my $self = shift;
>>     return $self->{TemplateObj} if !$self->{TemplateObj}
>>         || $self->{our_custom_code_has_made_the_change};
>>
>>     my $ticket = $self->TicketObj;
>>     return $self->{TemplateObj} unless $ticket;
>>
>>     my $orig_name = $self->{TemplateObj}->Name;
>>
>>     my $lang = $ticket->FirstCustomFieldValue('Language');
>>     my $case_type = $ticket->FirstCustomFieldValue('Category');
>>     foreach my $name ("$orig_name $case_type $lang", "$orig_name
>> $case_type $lang") {
>>          my $tmp = RT::Template->new( $self->CurrentUser );
>>          $tmp->Load( $name ); # queue should be here and fallback to
>> global!
>>          unless ($tmp->id) {
>>              RT->Logger->debug("No custom template $name");
>>          } else {
>>              $self->{TemplateObj} = $tmp;
>>          }
>>     }
>>     $self->{our_custom_code_has_made_the_change} = 1;
>>     return $self->{TemplateObj};
>> }
>>
>> On 4 October 2013 11:47, Landon Stewart <[email protected]> wrote:

> Hi Ruslan,
>
> Firstly, thank you!  This worked remarkably well.  I customized things a
> little to have it not be used unless it's the right type of notification
> etc but otherwise it was pretty much right on and works well.  My Scrips
> are all now deleted and there's just one in there now for this purpose and
> the template is properly selected based on the criteria used to make the
> $name variable.
>
> I have one question however…  What is the reason for the foreach loop in
> this code you provided.
>

One update to this…  I had to add a line to stop the sub from overriding if
the TransactionObj->Type is not Create

my $ticket = $self->TicketObj;
return $self->{TemplateObj} unless $ticket;
*return $self->{TemplateObj} unless $trans->Type eq "Create";*

Without this the template is overridden on correspondence as well.

-- 
Landon Stewart :: [email protected]
Lead Specialist, Abuse and Security Management
Spécialiste principal, gestion des abus et sécurité
http://iweb.com :: +1 (888) 909-4932
-- 
RT Training in New York, October 8th and 9th: http://bestpractical.com/training

Reply via email to