[rt-users] Back to my Dynamic template choosing Scrip problem...

Ruslan Zakirov ruz at bestpractical.com
Mon Oct 7 15:43:43 EDT 2013


On Mon, Oct 7, 2013 at 10:52 PM, Landon Stewart <lstewart at iweb.com> wrote:

> On 3 October 2013 04:27, Ruslan Zakirov <ruz at bestpractical.com> 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 <lstewart at iweb.com> 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.
>>
>
Typo in my code made it less clear, it should have been:

foreach my $name ("$orig_name $case_type $lang", "$orig_name $lang" ) {
...
}

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.

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.
>

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.

-- 
> Landon Stewart :: lstewart at iweb.com
> Lead Specialist, Abuse and Security Management
> Spécialiste principal, gestion des abus et sécurité
> http://iweb.com :: +1 (888) 909-4932
>
>
>


-- 
Best regards, Ruslan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20131007/646da7b0/attachment.htm>


More information about the rt-users mailing list