<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Oct 7, 2013 at 10:52 PM, Landon Stewart <span dir="ltr"><<a href="mailto:lstewart@iweb.com" target="_blank">lstewart@iweb.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">
<div><div class="h5"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div dir="ltr"><div>On 3 October 2013 04:27, Ruslan Zakirov <span dir="ltr"><<a href="mailto:ruz@bestpractical.com" target="_blank">ruz@bestpractical.com</a>></span> wrote:<br></div></div><div><div>

<div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr">Hi,<div><br></div><div>You can do this by inserting custom TemplateObj method into RT/Action/SendMail.pm</div><div><br></div><div>It should be like this:</div><div>1) behave like original method, so copy it from lib/RT/Action.pm</div>




<div>2) change template on call when Ticket and Txn are available</div><div>3) mark that change was done</div><div><br></div><div>For example:</div><div><br></div><div>sub TemplateObj {</div><div>    my $self = shift;</div>




<div>    return $self->{TemplateObj} if !$self->{TemplateObj}</div><div>        || $self->{our_custom_code_has_made_the_change};</div><div><div><br></div><div>    my $ticket = $self->TicketObj;</div>
</div><div>    return $self->{TemplateObj} unless $ticket;</div>
<div><br></div><div>    my $orig_name = $self->{TemplateObj}->Name;</div><div><br></div><div>    my $lang = $ticket->FirstCustomFieldValue('Language');</div><div>    my $case_type = $ticket->FirstCustomFieldValue('Category');</div>




<div>    foreach my $name ("$orig_name $case_type $lang", "$orig_name $case_type $lang") {</div><div>         my $tmp = RT::Template->new( $self->CurrentUser );</div><div>         $tmp->Load( $name ); # queue should be here and fallback to global!</div>




<div>         unless ($tmp->id) {</div><div>             RT->Logger->debug("No custom template $name");</div><div>         } else {</div><div>             $self->{TemplateObj} = $tmp;</div><div>         }</div>




<div>    }</div><div>    $self->{our_custom_code_has_made_the_change} = 1;</div><div>    return $self->{TemplateObj};</div><div>}</div><div><br></div></div></blockquote></div></div></div></div></blockquote></div></div>
On 4 October 2013 11:47, Landon Stewart <span dir="ltr"><<a href="mailto:lstewart@iweb.com" target="_blank">lstewart@iweb.com</a>></span> wrote:<div class="im"><br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Hi Ruslan,<div><br></div><div>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.</div>


<div><br></div><div>I have one question however…  What is the reason for the foreach loop in this code you provided.</div></div></blockquote></div></div></div></div></blockquote><div><br></div><div>Typo in my code made it less clear, it should have been:</div>
<div><br></div><div><span style="color:rgb(80,0,80)">foreach my $name ("$orig_name $case_type $lang", "$orig_name $lang" ) {</span></div><div><span style="color:rgb(80,0,80)">...</span></div><div><span style="color:rgb(80,0,80)">}</span><br>
</div><div><span style="color:rgb(80,0,80)"><br></span></div><div><font color="#500050">Idea is to look first for template with more detailed name, then look for name without case type, but language specific, then fallback to default in case all are absent.</font></div>
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">
<div>One update to this…  I had to add a line to stop the sub from overriding if the TransactionObj->Type is not Create</div><div class="im">

<div><br></div><div><div style="color:rgb(80,0,80)">my $ticket = $self->TicketObj;</div><div style="color:rgb(80,0,80)">return $self->{TemplateObj} unless $ticket;</div></div></div><div><i>return $self->{TemplateObj} unless $trans->Type eq "Create";</i></div>


<div><br></div><div>Without this the template is overridden on correspondence as well.<br></div></div></div></div></blockquote><div><br></div><div>Without type check you can use this to customize notifications for other txns, for example "Notify requestor on reply". I understand why you want it only for autoreplies. Your choice.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="im">
-- <br><div dir="ltr"><div><span style="font-family:arial;font-size:small">Landon Stewart :: </span><a href="mailto:lstewart@iweb.com" style="font-family:arial;font-size:small" target="_blank">lstewart@iweb.com</a><br>

</div><span style="font-family:arial;font-size:small">Lead Specialist, Abuse and Security Management</span><br style="font-family:arial;font-size:small"><span style="font-family:arial;font-size:small">Spécialiste principal, gestion des abus et sécurité</span><br style="font-family:arial;font-size:small">


<span style="font-family:arial;font-size:small"><a href="http://iweb.com" target="_blank">http://iweb.com</a> :: +1 (888) 909-4932</span><br><div><span style="font-family:arial;font-size:small"><br></span></div><div><span style="font-family:arial;font-size:small"><br>


</span></div></div>
</div></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Best regards, Ruslan.
</div></div>